diff options
Diffstat (limited to 'spec/frontend/serverless/store')
-rw-r--r-- | spec/frontend/serverless/store/actions_spec.js | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/spec/frontend/serverless/store/actions_spec.js b/spec/frontend/serverless/store/actions_spec.js index 61b9bd121af..5fbecf081a6 100644 --- a/spec/frontend/serverless/store/actions_spec.js +++ b/spec/frontend/serverless/store/actions_spec.js @@ -7,13 +7,22 @@ import { mockServerlessFunctions, mockMetrics } from '../mock_data'; import { adjustMetricQuery } from '../utils'; describe('ServerlessActions', () => { + let mock; + + beforeEach(() => { + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + }); + describe('fetchFunctions', () => { - it('should successfully fetch functions', (done) => { + it('should successfully fetch functions', () => { const endpoint = '/functions'; - const mock = new MockAdapter(axios); mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockServerlessFunctions)); - testAction( + return testAction( fetchFunctions, { functionsPath: endpoint }, {}, @@ -22,68 +31,49 @@ describe('ServerlessActions', () => { { type: 'requestFunctionsLoading' }, { type: 'receiveFunctionsSuccess', payload: mockServerlessFunctions }, ], - () => { - mock.restore(); - done(); - }, ); }); - it('should successfully retry', (done) => { + it('should successfully retry', () => { const endpoint = '/functions'; - const mock = new MockAdapter(axios); mock .onGet(endpoint) .reply(() => new Promise((resolve) => setTimeout(() => resolve(200), Infinity))); - testAction( + return testAction( fetchFunctions, { functionsPath: endpoint }, {}, [], [{ type: 'requestFunctionsLoading' }], - () => { - mock.restore(); - done(); - }, ); }); }); describe('fetchMetrics', () => { - it('should return no prometheus', (done) => { + it('should return no prometheus', () => { const endpoint = '/metrics'; - const mock = new MockAdapter(axios); mock.onGet(endpoint).reply(statusCodes.NO_CONTENT); - testAction( + return testAction( fetchMetrics, { metricsPath: endpoint, hasPrometheus: false }, {}, [], [{ type: 'receiveMetricsNoPrometheus' }], - () => { - mock.restore(); - done(); - }, ); }); - it('should successfully fetch metrics', (done) => { + it('should successfully fetch metrics', () => { const endpoint = '/metrics'; - const mock = new MockAdapter(axios); mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockMetrics)); - testAction( + return testAction( fetchMetrics, { metricsPath: endpoint, hasPrometheus: true }, {}, [], [{ type: 'receiveMetricsSuccess', payload: adjustMetricQuery(mockMetrics) }], - () => { - mock.restore(); - done(); - }, ); }); }); |