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
This commit is contained in:
Fatih Acet 2016-11-08 14:00:34 +00:00
commit 5db9c791e5
3 changed files with 139 additions and 131 deletions

View file

@ -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 @@
}); });
}); });
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 @@
}, 0); }, 0);
}); });
}); });
}); });
})();

View file

@ -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);

View file

@ -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
})); }));
}); };