Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Jun 14, 2023
1 parent ee72e15 commit 80ce5e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
8 changes: 4 additions & 4 deletions __tests__/Auth0Client/handleRedirectCallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Auth0Client', () => {
expect(error.error).toBe('some-error');
expect(error.error_description).toBe('some-error-description');
expect(error.state).toBe('error-state');
expect(error.appState).toBe(appState);
expect(error.appState).toEqual(appState);
});

it('should clear the transaction data when the /authorize call redirects with a code param', async () => {
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Auth0Client', () => {
const result = await loginWithRedirect(auth0, { appState });

expect(result).toBeDefined();
expect(result.appState).toBe(appState);
expect(result.appState).toEqual(appState);
});

it('uses the custom http timeout value if specified', async () => {
Expand All @@ -234,7 +234,7 @@ describe('Auth0Client', () => {

expect((http.switchFetch as jest.Mock).mock.calls[0][6]).toEqual(40000);
expect(result).toBeDefined();
expect(result.appState).toBe(appState);
expect(result.appState).toEqual(appState);
});

it('does not store the scope from token endpoint if none was returned', async () => {
Expand Down Expand Up @@ -456,7 +456,7 @@ describe('Auth0Client', () => {
expect(error.error).toBe('some-error');
expect(error.error_description).toBe('some-error-description');
expect(error.state).toBe('error-state');
expect(error.appState).toBe(appState);
expect(error.appState).toEqual(appState);
});

it('should clear the transaction data when the /authorize call redirects with a code param', async () => {
Expand Down
4 changes: 3 additions & 1 deletion __tests__/Auth0Client/loginWithRedirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
} from '../constants';
import version from '../../src/version';

jest.mock('es-cookie');
jest.mock('../../src/jwt');
jest.mock('../../src/worker/token.worker');

Expand All @@ -59,6 +58,9 @@ describe('Auth0Client', () => {
const oldWindowLocation = window.location;

beforeEach(() => {
jest.spyOn(mockCookies, 'get');
jest.spyOn(mockCookies, 'set');
jest.spyOn(mockCookies, 'remove');
// https://www.benmvp.com/blog/mocking-window-location-methods-jest-jsdom/
delete window.location;
window.location = Object.defineProperties(
Expand Down
32 changes: 16 additions & 16 deletions __tests__/transaction-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ describe('transaction manager', () => {
jest.resetAllMocks();
});

describe('constructor', () => {
describe('get', () => {
it('loads transactions from storage (per key)', () => {
tm = new TransactionManager(SessionStorage, TEST_CLIENT_ID);

tm.get();

expect(sessionStorage.getItem).toHaveBeenCalledWith(transactionKey());
});
});
Expand Down Expand Up @@ -59,7 +62,7 @@ describe('transaction manager', () => {
});

it('`get` with a transaction should return the transaction', () => {
tm.create(transaction);
jest.mocked(sessionStorage.getItem).mockReturnValue(transactionJson);
expect(tm.get()).toMatchObject(transaction);
});

Expand All @@ -81,11 +84,11 @@ describe('transaction manager', () => {
expect(sessionStorage.removeItem).toHaveBeenCalledWith(transactionKey());
});
});
describe('CookieStorage usage', () => {
it("`create` saves the transaction in the storage with the provided domain", () => {

describe('CookieStorage usage', () => {
it('`create` saves the transaction in the storage with the provided domain', () => {
CookieStorage.save = jest.fn();
const cookieDomain = "vanity.auth.com";
const cookieDomain = 'vanity.auth.com';
tm = new TransactionManager(CookieStorage, TEST_CLIENT_ID, cookieDomain);
tm.create(transaction);

Expand All @@ -99,18 +102,15 @@ describe('transaction manager', () => {
);
});

it("`remove` deletes the transaction in the storage with the provided domain", () => {
it('`remove` deletes the transaction in the storage with the provided domain', () => {
CookieStorage.remove = jest.fn();
const cookieDomain = "vanity.auth.com";
const cookieDomain = 'vanity.auth.com';
tm = new TransactionManager(CookieStorage, TEST_CLIENT_ID, cookieDomain);
tm.remove();

expect(CookieStorage.remove).toHaveBeenCalledWith(
transactionKey(),
{
cookieDomain: cookieDomain
}
);
});
});
expect(CookieStorage.remove).toHaveBeenCalledWith(transactionKey(), {
cookieDomain: cookieDomain
});
});
});
});

0 comments on commit 80ce5e5

Please sign in to comment.