1
Ich habe eine kleine redux
Middleware wie soWie ein Import mit Scherz
import { hashHistory } from 'react-router'
import { REDIRECT_TO_LOGIN_REDIRECT_URL } from '../actions/login-redirect';
export default store => next => action => {
if (action.type === REDIRECT_TO_LOGIN_REDIRECT_URL) {
hashHistory.push(store.getState().loginRedirectUrl);
}
return next(action)
}
verspotten, die ich jetzt testen möchten. Wie Sie in Zeile 1 sehen können, importiere ich hashHistory
und benutze es später. Dies möchte ich testen (der Anruf an hashHistory
). Um das zu tun, müsste ich hashHistory
vortäuschen, aber ich weiß nicht wie. Ich verwende jest
:
import { REDIRECT_TO_LOGIN_REDIRECT_URL } from '../actions/login-redirect';
import redirectMiddleware from './redirect-after-login';
describe('redirect after login middleware',() => {
function setup() {
const store = {
subscribe:() => {},
dispatch:() => {},
getState:() => ({})
};
const next = jest.fn();
const action = { type: REDIRECT_TO_LOGIN_REDIRECT_URL };
return { store, next, action };
}
it('should push the redirect URL to the hashHistory',() => {
// How to test it?
})
});
perfekte Antwort! Vielen Dank! – Lukas