Created
May 17, 2019 13:54
-
-
Save robneville73/d47ae0a02bc4d427df5015c6980054b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('router interceptor tests', () => { | |
describe('if unauthenticated, store to route and go to login route', () => { | |
// :shrug: I have no idea why you have to do it like this | |
// and only here?? | |
store.getters = { | |
'auth/authenticated': false | |
}; | |
const to = { name: 'blah' }; | |
let nextObj = { | |
next: function () { | |
return null; | |
} | |
}; | |
const nextSpy = jest.spyOn(nextObj, 'next'); | |
const dispatchSpy = jest.spyOn(store, 'dispatch'); | |
interceptor(to, {}, nextObj.next); | |
expect(nextSpy).toHaveBeenCalled(); | |
expect(dispatchSpy).toBeCalledTimes(1); | |
expect(dispatchSpy.mock.calls[0]).toEqual([ | |
"auth/rememberEntryRoute", | |
to | |
]); | |
expect(nextSpy.mock.calls[0]).toEqual([{ name: 'login' }]); | |
}); | |
describe('if unauthenticated but going to login, just go on', () => { | |
store.getters = { | |
'auth/authenticated': false | |
}; | |
const to2 = { name: 'login' }; | |
let nextObj = { | |
next: function () { | |
return null; | |
} | |
}; | |
// const nextSpy = jest.spyOn(nextObj, 'next'); | |
const dispatchSpy2 = jest.spyOn(store, 'dispatch'); | |
interceptor(to2, {}, nextObj.next); | |
expect(dispatchSpy2).toBeCalledTimes(0); | |
}); | |
// describe('if authenticated, just go on', () => { | |
// null; | |
// }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
putting console logs in the interceptor function shows that to == { name: 'blah' } in the second test... if I comment out test 1, it works.