Commit c16d5bcd authored by winniehell's avatar winniehell

Move Ajax interceptor into describe block (!7304)

parent 50f3fd49
...@@ -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