Commit ea6fb669 authored by Thomas Randolph's avatar Thomas Randolph

Move mock setup and teardown to before/after each

parent 573a9175
...@@ -174,9 +174,18 @@ describe('DiffsStoreActions', () => { ...@@ -174,9 +174,18 @@ describe('DiffsStoreActions', () => {
}); });
describe('fetchDiffFilesBatch', () => { describe('fetchDiffFilesBatch', () => {
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
it('should fetch batch diff files', done => { it('should fetch batch diff files', done => {
const endpointBatch = '/fetch/diffs_batch'; const endpointBatch = '/fetch/diffs_batch';
const mock = new MockAdapter(axios);
const res1 = { diff_files: [], pagination: { next_page: 2 } }; const res1 = { diff_files: [], pagination: { next_page: 2 } };
const res2 = { diff_files: [], pagination: {} }; const res2 = { diff_files: [], pagination: {} };
mock mock
...@@ -219,10 +228,7 @@ describe('DiffsStoreActions', () => { ...@@ -219,10 +228,7 @@ describe('DiffsStoreActions', () => {
{ type: types.SET_RETRIEVING_BATCHES, payload: false }, { type: types.SET_RETRIEVING_BATCHES, payload: false },
], ],
[], [],
() => { done,
mock.restore();
done();
},
); );
}); });
...@@ -234,7 +240,6 @@ describe('DiffsStoreActions', () => { ...@@ -234,7 +240,6 @@ describe('DiffsStoreActions', () => {
'should make a request with the view parameter "$viewStyle" when the batchEndpoint already contains "$otherView"', 'should make a request with the view parameter "$viewStyle" when the batchEndpoint already contains "$otherView"',
({ viewStyle, otherView }) => { ({ viewStyle, otherView }) => {
const endpointBatch = '/fetch/diffs_batch'; const endpointBatch = '/fetch/diffs_batch';
const mock = new MockAdapter(axios);
fetchDiffFilesBatch({ fetchDiffFilesBatch({
commit: () => {}, commit: () => {},
...@@ -247,7 +252,6 @@ describe('DiffsStoreActions', () => { ...@@ -247,7 +252,6 @@ describe('DiffsStoreActions', () => {
.then(() => { .then(() => {
expect(mock.history.get[0].url).toContain(`view=${viewStyle}`); expect(mock.history.get[0].url).toContain(`view=${viewStyle}`);
expect(mock.history.get[0].url).not.toContain(`view=${otherView}`); expect(mock.history.get[0].url).not.toContain(`view=${otherView}`);
mock.restore();
}) })
.catch(() => {}); .catch(() => {});
}, },
...@@ -322,9 +326,18 @@ describe('DiffsStoreActions', () => { ...@@ -322,9 +326,18 @@ describe('DiffsStoreActions', () => {
}); });
describe('fetchDiffFilesBatch', () => { describe('fetchDiffFilesBatch', () => {
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
it('should fetch batch diff files', done => { it('should fetch batch diff files', done => {
const endpointBatch = '/fetch/diffs_batch'; const endpointBatch = '/fetch/diffs_batch';
const mock = new MockAdapter(axios);
const res1 = { diff_files: [], pagination: { next_page: 2 } }; const res1 = { diff_files: [], pagination: { next_page: 2 } };
const res2 = { diff_files: [], pagination: {} }; const res2 = { diff_files: [], pagination: {} };
mock mock
...@@ -347,10 +360,7 @@ describe('DiffsStoreActions', () => { ...@@ -347,10 +360,7 @@ describe('DiffsStoreActions', () => {
{ type: types.SET_RETRIEVING_BATCHES, payload: false }, { type: types.SET_RETRIEVING_BATCHES, payload: false },
], ],
[], [],
() => { done,
mock.restore();
done();
},
); );
}); });
...@@ -363,7 +373,6 @@ describe('DiffsStoreActions', () => { ...@@ -363,7 +373,6 @@ describe('DiffsStoreActions', () => {
'should use the endpoint $requestUrl if the endpointBatch in state includes `$querystrings` as a querystring', 'should use the endpoint $requestUrl if the endpointBatch in state includes `$querystrings` as a querystring',
({ querystrings, requestUrl }) => { ({ querystrings, requestUrl }) => {
const endpointBatch = '/fetch/diffs_batch'; const endpointBatch = '/fetch/diffs_batch';
const mock = new MockAdapter(axios);
fetchDiffFilesBatch({ fetchDiffFilesBatch({
commit: () => {}, commit: () => {},
...@@ -374,7 +383,6 @@ describe('DiffsStoreActions', () => { ...@@ -374,7 +383,6 @@ describe('DiffsStoreActions', () => {
}) })
.then(() => { .then(() => {
expect(mock.history.get[0].url).toEqual(requestUrl); expect(mock.history.get[0].url).toEqual(requestUrl);
mock.restore();
}) })
.catch(() => {}); .catch(() => {});
}, },
......
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