I have this module with a function in it:
const utils = {
redirectTo(url) {
if (url) {
window.location = url;
}
},
};
export default utils;
It is used somewhere in a React component like this:
import utils from '../../lib/utils';
componentWillUpdate() {
this.redirectTo('foo')
}
Now I want to check that the value that redirectTo
is called with equals foo
.
it('should redirect if no rights', () => {
const mockRedirectFn = jest.fn();
utils.redirectTo = mockRedirectFn;
mount(
<SomeComponent />,
);
expect(mockRedirectFn).toBeCalled();
expect(mockRedirectFn).toBeCalledWith('foo');
console.log(mockRedirectFn.mock);
// { calls: [], instances: [] }
});
Thats what I've got and it does not work. How do I do this?