When using watch (npm run test -- --watch
), I had to save and restore the original router.browserHistory
to avoid the Invariant Violation
(below).
import * as router from 'react-router'
describe('some description', () => {
const oldBrowserHistory = router.browserHistory
after(() => { router.browserHistory = oldBrowserHistory })
it('some expectation', () => {
const spy = sinon.spy()
router.browserHistory = { push: spy }
// call your code here
expect(spy.withArgs(expectedArgs).calledOnce).to.be.true
})
})
Invariant Violation: You have provided a history object created with history v2.x or earlier. This version of React Router is only compatible with v3 history objects. Please upgrade to history v3.x.
(credit to user3682091 for getting me started on the correct path)
router
instead of justbrowserHistory
orhashHistory
, which is how I was trying to mock it. – Logwood