Skip to content

Commit 41157fc

Browse files
test(browserHistory): Mock history for phantomJS spyOn history
1 parent e324973 commit 41157fc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/vanilla.browserHistorySpec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ describe('browserHistory implementation', () => {
99
let makeMatcher;
1010
let locationProvider = services.location;
1111

12+
// for phantomJS
13+
function mockHistoryObject() {
14+
(window as any).history = {
15+
replaceState: () => null,
16+
pushState: () => null
17+
};
18+
}
19+
1220
beforeEach(() => {
1321
router = new UIRouter();
1422
router.plugin(vanilla.services);
@@ -25,13 +33,15 @@ describe('browserHistory implementation', () => {
2533
});
2634

2735
it('uses history.pushState when setting a url', () => {
36+
mockHistoryObject();
2837
expect(services.locationConfig.html5Mode()).toBe(true);
2938
let stub = spyOn(history, 'pushState');
3039
router.urlRouter.push(makeMatcher('/hello/:name'), { name: 'world' });
3140
expect(stub.calls.first().args[2]).toBe('/hello/world');
3241
});
3342

3443
it('uses history.replaceState when setting a url with replace', () => {
44+
mockHistoryObject();
3545
let stub = spyOn(history, 'replaceState');
3646
router.urlRouter.push(makeMatcher('/hello/:name'), { name: 'world' }, { replace: true });
3747
expect(stub.calls.first().args[2]).toBe('/hello/world');

0 commit comments

Comments
 (0)