Skip to content

Commit

Permalink
Fix unit tests #354
Browse files Browse the repository at this point in the history
  • Loading branch information
tswinb committed Aug 19, 2020
1 parent 404fab2 commit 9b4d7b3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,18 @@ if (typeof window.URL.createObjectURL === 'undefined') {
Object.defineProperty(window.URL, 'createObjectURL', { value: noOp });
}

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});

export const flushPromises = (): Promise<void> => new Promise(setImmediate);
8 changes: 4 additions & 4 deletions src/state/actions/scigateway.actions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('scigateway actions', () => {

await asyncAction(dispatch, getState);

expect(actions[1]).toEqual(
expect(actions[2]).toEqual(
loadFeatureSwitches({ showContactButton: true })
);
});
Expand All @@ -211,7 +211,7 @@ describe('scigateway actions', () => {

await asyncAction(dispatch, getState);

expect(actions[0]).toEqual(configureAnalytics('test-tracking-id'));
expect(actions[1]).toEqual(configureAnalytics('test-tracking-id'));
});

it('dispatches a site loading update after settings are loaded', async () => {
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('scigateway actions', () => {

await asyncAction(dispatch, getState);

expect(actions.length).toEqual(6);
expect(actions.length).toEqual(7);
expect(actions).toContainEqual(authorised());
expect(actions).toContainEqual(siteLoadingUpdate(false));
});
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('scigateway actions', () => {

await asyncAction(dispatch, getState);

expect(actions.length).toEqual(5);
expect(actions.length).toEqual(6);
expect(actions).toContainEqual(invalidToken());
expect(actions).toContainEqual(siteLoadingUpdate(false));
});
Expand Down
7 changes: 6 additions & 1 deletion src/state/middleware/scigateway.middleware.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ describe('scigateway middleware', () => {
});

it('should send dark theme options when LoadDarkModePreferenceType action is sent and darkmode preference is true', () => {
Storage.prototype.getItem = jest.fn(() => 'true');
const loadDarkModePreferenceAction = {
type: LoadDarkModePreferenceType,
payload: {
darkMode: true,
},
};

const theme = buildTheme(true);

Expand Down

0 comments on commit 9b4d7b3

Please sign in to comment.