|
1 | 1 | var testUtils = require('../util') |
2 | 2 | var test = testUtils.test |
3 | 3 | var assertCalls = testUtils.assertCalls |
| 4 | +var routerUtil = require('../../../../src/util') |
4 | 5 |
|
5 | 6 | describe('activate', function () { |
6 | 7 |
|
| 8 | + beforeEach(function () { |
| 9 | + spyOn(routerUtil, 'warn') |
| 10 | + }) |
| 11 | + |
7 | 12 | it('sync', function (done) { |
8 | 13 | test({ |
9 | 14 | a: { |
@@ -117,11 +122,35 @@ describe('activate', function () { |
117 | 122 | // path changes during validation phase |
118 | 123 | expect(router.history.currentPath).toBe('/a') |
119 | 124 | setTimeout(function () { |
120 | | - // but gets reset when validation fails |
121 | | - expect(router.app.$el.textContent).toBe('') |
122 | | - expect(router.history.currentPath).toBe('/') |
| 125 | + // activation error should continue transition |
| 126 | + expect(router.app.$el.textContent).toBe('A ') |
| 127 | + expect(router.history.currentPath).toBe('/a') |
123 | 128 | done() |
124 | 129 | }, wait * 2) |
125 | 130 | }) |
126 | 131 | }) |
| 132 | + |
| 133 | + it('error', function (done) { |
| 134 | + test({ |
| 135 | + a: { |
| 136 | + activate: function (transition) { |
| 137 | + throw new Error('oh no') |
| 138 | + } |
| 139 | + } |
| 140 | + }, function (router, calls, emitter) { |
| 141 | + var errorThrown = jasmine.createSpy() |
| 142 | + try { |
| 143 | + router.go('/a') |
| 144 | + } catch (e) { |
| 145 | + errorThrown() |
| 146 | + } |
| 147 | + expect(routerUtil.warn).toHaveBeenCalled() |
| 148 | + expect(errorThrown).toHaveBeenCalled() |
| 149 | + // should complete the transition despite error |
| 150 | + assertCalls(calls, ['a.activate']) |
| 151 | + expect(router.app.$el.textContent).toBe('A ') |
| 152 | + expect(router.history.currentPath).toBe('/a') |
| 153 | + done() |
| 154 | + }) |
| 155 | + }) |
127 | 156 | }) |
0 commit comments