|
| 1 | +import Router from '../../../src/index' |
| 2 | + |
| 3 | +fdescribe('Programmatic navigation callbacks', () => { |
| 4 | + let calls = [] |
| 5 | + let router, spy1, spy2 |
| 6 | + |
| 7 | + const Foo = { |
| 8 | + beforeRouteEnter (to, from, next) { |
| 9 | + calls.push(3) |
| 10 | + setTimeout(() => { |
| 11 | + calls.push(4) |
| 12 | + next() |
| 13 | + }, 1) |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + beforeEach(() => { |
| 18 | + calls = [] |
| 19 | + spy1 = jasmine.createSpy('complete') |
| 20 | + spy2 = jasmine.createSpy('abort') |
| 21 | + |
| 22 | + router = new Router({ |
| 23 | + routes: [ |
| 24 | + { path: '/foo', component: Foo } |
| 25 | + ] |
| 26 | + }) |
| 27 | + |
| 28 | + router.beforeEach((to, from, next) => { |
| 29 | + calls.push(1) |
| 30 | + setTimeout(() => { |
| 31 | + calls.push(2) |
| 32 | + next() |
| 33 | + }, 1) |
| 34 | + }) |
| 35 | + }) |
| 36 | + |
| 37 | + it('push complete', done => { |
| 38 | + router.push('/foo', () => { |
| 39 | + expect(calls).toEqual([1, 2, 3, 4]) |
| 40 | + done() |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
| 44 | + it('push abort', done => { |
| 45 | + router.push('/foo', spy1, spy2) |
| 46 | + router.push('/bar', () => { |
| 47 | + expect(calls).toEqual([1, 1, 2, 2]) |
| 48 | + expect(spy1).not.toHaveBeenCalled() |
| 49 | + expect(spy2).toHaveBeenCalled() |
| 50 | + done() |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + it('replace complete', done => { |
| 55 | + router.replace('/foo', () => { |
| 56 | + expect(calls).toEqual([1, 2, 3, 4]) |
| 57 | + done() |
| 58 | + }) |
| 59 | + }) |
| 60 | + |
| 61 | + it('replace abort', done => { |
| 62 | + router.replace('/foo', spy1, spy2) |
| 63 | + router.replace('/bar', () => { |
| 64 | + expect(calls).toEqual([1, 1, 2, 2]) |
| 65 | + expect(spy1).not.toHaveBeenCalled() |
| 66 | + expect(spy2).toHaveBeenCalled() |
| 67 | + done() |
| 68 | + }) |
| 69 | + }) |
| 70 | +}) |
0 commit comments