refactor: remove sinon (#42337)

This commit is contained in:
Oliver Eyton-Williams
2021-06-02 17:33:05 +02:00
committed by GitHub
parent 7d1e9af9df
commit 802273cf8a
8 changed files with 91 additions and 195 deletions

View File

@@ -5,7 +5,7 @@ import {
setAccessTokenToResponse,
removeCookies
} from './getSetAccessToken';
import { mockReq, mockRes } from 'sinon-express-mock';
import { mockReq, mockRes } from '../boot_tests/challenge.test';
import jwt from 'jsonwebtoken';
describe('getSetAccessToken', () => {
@@ -130,7 +130,8 @@ describe('getSetAccessToken', () => {
setAccessTokenToResponse({ accessToken }, req, res, validJWTSecret);
expect(res.cookie.getCall(0).args).toEqual([
expect(res.cookie).toHaveBeenNthCalledWith(
1,
'jwt_access_token',
expectedJWT,
{
@@ -138,7 +139,7 @@ describe('getSetAccessToken', () => {
domain,
maxAge: accessToken.ttl
}
]);
);
});
});
@@ -152,16 +153,18 @@ describe('getSetAccessToken', () => {
removeCookies(req, res);
expect(res.clearCookie.getCall(0).args).toEqual([
expect(res.clearCookie).toHaveBeenNthCalledWith(
1,
'jwt_access_token',
jwtOptions
]);
expect(res.clearCookie.getCall(1).args).toEqual([
);
expect(res.clearCookie).toHaveBeenNthCalledWith(
2,
'access_token',
jwtOptions
]);
expect(res.clearCookie.getCall(2).args).toEqual(['userId', jwtOptions]);
expect(res.clearCookie.getCall(3).args).toEqual(['_csrf', jwtOptions]);
);
expect(res.clearCookie).toHaveBeenNthCalledWith(3, 'userId', jwtOptions);
expect(res.clearCookie).toHaveBeenNthCalledWith(4, '_csrf', jwtOptions);
});
});
});

View File

@@ -1,6 +1,5 @@
/* global describe beforeEach expect it */
/* global describe beforeEach expect it jest */
import inMemoryCache from './in-memory-cache';
import sinon from 'sinon';
describe('InMemoryCache', () => {
let reportErrorStub;
@@ -10,7 +9,7 @@ describe('InMemoryCache', () => {
const emptyCacheValue = null;
beforeEach(() => {
reportErrorStub = sinon.spy();
reportErrorStub = jest.fn();
});
it('throws if no report function is passed as a second argument', () => {
@@ -43,7 +42,6 @@ describe('InMemoryCache', () => {
});
it('reports errors thrown from the update function', () => {
const reportErrorStub = sinon.spy();
const cache = inMemoryCache(before, reportErrorStub);
const updateError = new Error('An update error');
@@ -52,7 +50,7 @@ describe('InMemoryCache', () => {
};
cache.update(updateThatThrows);
expect(reportErrorStub.calledWith(updateError)).toBe(true);
expect(reportErrorStub).toHaveBeenCalledWith(updateError);
});
});

View File

@@ -1,6 +1,5 @@
/* global describe it expect afterAll */
/* global describe it expect jest */
import moment from 'moment-timezone';
import sinon from 'sinon';
import {
prepUniqueDaysByHours,
@@ -10,13 +9,13 @@ import {
} from './user-stats';
import { mockUserID, mockApp, mockUser } from '../boot_tests/fixtures';
// setting now to 2016-02-03T11:00:00 (PST)
const clock = sinon.useFakeTimers(1454526000000);
jest.useFakeTimers('modern');
const PST = 'America/Los_Angeles';
describe('user stats', () => {
afterAll(() => {
clock.restore();
beforeEach(() => {
// setting now to 2016-02-03T11:00:00 (PST)
jest.setSystemTime(1454526000000);
});
describe('prepUniqueDaysByHours', () => {