Commit 17651e21 authored by Alexander Turinske's avatar Alexander Turinske

Refactor security dashboard getter test mocks

- use cleaner implementation
parent d90a33f4
...@@ -169,8 +169,7 @@ describe('filters actions', () => { ...@@ -169,8 +169,7 @@ describe('filters actions', () => {
}, },
].forEach(testCase => { ].forEach(testCase => {
it(testCase.description, done => { it(testCase.description, done => {
const mockValue = testCase.returnValue; getParameterValues.mockReturnValue(testCase.returnValue);
getParameterValues.mockImplementation(() => mockValue);
const state = createState(); const state = createState();
testAction( testAction(
actions.setHideDismissedToggleInitialState, actions.setHideDismissedToggleInitialState,
......
...@@ -65,26 +65,17 @@ describe('vulnerabilities module getters', () => { ...@@ -65,26 +65,17 @@ describe('vulnerabilities module getters', () => {
getters.getVulnerabilityHistoryByName(state)(name); getters.getVulnerabilityHistoryByName(state)(name);
return { getVulnerabilityHistoryByName }; return { getVulnerabilityHistoryByName };
}; };
const realDate = Date;
beforeEach(() => { beforeEach(() => {
state = createState(); state = createState();
state.vulnerabilitiesHistory = mockHistoryData; state.vulnerabilitiesHistory = mockHistoryData;
jest.useFakeTimers();
const currentDate = new Date(2019, 1, 2);
global.Date = class extends Date {
constructor(date) {
if (date) {
// eslint-disable-next-line constructor-super
return super(date);
}
return currentDate;
}
};
});
afterEach(() => { const mockDate = new Date(2019, 1, 2);
global.Date = realDate; const originalDate = Date;
jest.spyOn(global, 'Date').mockImplementation(() => mockDate);
global.Date.now = originalDate.now;
global.Date.parse = originalDate.parse;
global.Date.UTC = originalDate.UTC;
}); });
it('should filter the data to the last 30 days and days we have data for', () => { it('should filter the data to the last 30 days and days we have data for', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment