Commit 5db9c791 authored by Fatih Acet's avatar Fatih Acet

Merge branch 'move-boards-interceptor' into 'master'

Move Ajax interceptor into describe block

## What does this MR do?

Move registering the Vue resource interceptor for issue board mock data into the corresponding `describe` blocks.

## Why was this MR needed?

Currently, the interceptor is registered for every test (which makes them at best fail for Ajax calls using Vue resource).

See merge request !7304
parents 35142a09 c16d5bcd
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
//= require boards/stores/boards_store //= require boards/stores/boards_store
//= require ./mock_data //= require ./mock_data
(() => { describe('Store', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(boardsMockInterceptor);
gl.boardService = new BoardService('/test/issue-boards/board', '1'); gl.boardService = new BoardService('/test/issue-boards/board', '1');
gl.issueBoards.BoardsStore.create(); gl.issueBoards.BoardsStore.create();
...@@ -24,7 +25,10 @@ ...@@ -24,7 +25,10 @@
}); });
}); });
describe('Store', () => { afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, boardsMockInterceptor);
});
it('starts with a blank state', () => { it('starts with a blank state', () => {
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0); expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
}); });
...@@ -164,5 +168,4 @@ ...@@ -164,5 +168,4 @@
}, 0); }, 0);
}); });
}); });
}); });
})();
...@@ -17,12 +17,17 @@ describe('List model', () => { ...@@ -17,12 +17,17 @@ describe('List model', () => {
let list; let list;
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(boardsMockInterceptor);
gl.boardService = new BoardService('/test/issue-boards/board', '1'); gl.boardService = new BoardService('/test/issue-boards/board', '1');
gl.issueBoards.BoardsStore.create(); gl.issueBoards.BoardsStore.create();
list = new List(listObj); list = new List(listObj);
}); });
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, boardsMockInterceptor);
});
it('gets issues when created', (done) => { it('gets issues when created', (done) => {
setTimeout(() => { setTimeout(() => {
expect(list.issues.length).toBe(1); expect(list.issues.length).toBe(1);
......
...@@ -48,10 +48,10 @@ const BoardsMockData = { ...@@ -48,10 +48,10 @@ const BoardsMockData = {
} }
}; };
Vue.http.interceptors.push((request, next) => { const boardsMockInterceptor = (request, next) => {
const body = BoardsMockData[request.method][request.url]; const body = BoardsMockData[request.method][request.url];
next(request.respondWith(JSON.stringify(body), { next(request.respondWith(JSON.stringify(body), {
status: 200 status: 200
})); }));
}); };
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