Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky frontend unit tests #939

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ limitations under the License.
*/

module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: [
'<rootDir>/src/**/*.js',
Expand All @@ -33,6 +34,7 @@ module.exports = {
'<rootDir>/config_frontend/__mocks__/fileMock.js',
'\\.(css|scss)$': '<rootDir>/config_frontend/__mocks__/styleMock.js'
},
restoreMocks: true,
setupFilesAfterEnv: ['<rootDir>/config_frontend/setupTests.js'],
testMatch: [
'<rootDir>/src/**/*.test.js',
Expand Down
3 changes: 3 additions & 0 deletions src/actions/secrets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ it('fetchSecrets error', async () => {

const error = new Error('Could not fetch secrets');

jest
.spyOn(selectors, 'getSelectedNamespace')
.mockImplementation(() => namespace);
jest.spyOn(API, 'getCredentials').mockImplementation(() => {
throw error;
});
Expand Down
16 changes: 8 additions & 8 deletions src/actions/tasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
fetchTasks
} from './tasks';

it('fetchTask', async () => {
it('fetchTask', () => {
jest.spyOn(creators, 'fetchNamespacedResource');
const name = 'taskName';
const namespace = 'namespace';
Expand All @@ -33,7 +33,7 @@ it('fetchTask', async () => {
);
});

it('fetchTasks', async () => {
it('fetchTasks', () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
const namespace = 'namespace';
fetchTasks({ namespace });
Expand All @@ -44,7 +44,7 @@ it('fetchTasks', async () => {
);
});

it('fetchTasks no params', async () => {
it('fetchTasks no params', () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
fetchTasks();
expect(creators.fetchNamespacedCollection).toHaveBeenCalledWith(
Expand All @@ -54,7 +54,7 @@ it('fetchTasks no params', async () => {
);
});

it('fetchClusterTask', async () => {
it('fetchClusterTask', () => {
jest.spyOn(creators, 'fetchResource');
const name = 'clusterTaskName';
fetchClusterTask(name);
Expand All @@ -65,7 +65,7 @@ it('fetchClusterTask', async () => {
);
});

it('fetchClusterTasks', async () => {
it('fetchClusterTasks', () => {
jest.spyOn(creators, 'fetchCollection');
fetchClusterTasks();
expect(creators.fetchCollection).toHaveBeenCalledWith(
Expand All @@ -74,7 +74,7 @@ it('fetchClusterTasks', async () => {
);
});

it('fetchClusterTaskByType', async () => {
it('fetchClusterTaskByType', () => {
jest.spyOn(creators, 'fetchResource');
const name = 'clusterTaskName';
fetchTaskByType(name, 'clustertasks');
Expand All @@ -85,11 +85,11 @@ it('fetchClusterTaskByType', async () => {
);
});

it('fetchTaskByType', async () => {
it('fetchTaskByType', () => {
jest.spyOn(creators, 'fetchResource');
const name = 'clusterTaskName';

jest.spyOn(creators, 'fetchNamespacedCollection');
jest.spyOn(creators, 'fetchNamespacedResource');
const namespace = 'namespace';
fetchTaskByType(name, 'tasks', namespace);
expect(creators.fetchNamespacedResource).toHaveBeenCalledWith(
Expand Down
2 changes: 0 additions & 2 deletions src/api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import fetchMock from 'fetch-mock';
import * as comms from './comms';
import * as index from '.';

beforeEach(jest.resetAllMocks);

describe('getAPIRoot', () => {
it('handles base URL with trailing slash', () => {
window.history.pushState({}, 'Title', '/path/#hash');
Expand Down
Loading