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
// reducer.js | |
export const initialState = { | |
authenticated: false, | |
authenticating: false, | |
}; | |
export const loginReducer = ( | |
state = initialState, | |
action | |
) => { | |
switch (action.type) { | |
case AUTHENTICATION.AUTHENTICATED: | |
return { ...state, authenticating: false, authenticated: action.payload.authenticated }; | |
default: | |
return state; | |
} | |
}; | |
// action.js | |
export const switchAuthenticatedFlag = status => { | |
return { | |
type: 'LOGIN/AUTHENTICATED', | |
payload: { | |
authenticated: status, | |
}, | |
}; | |
}; | |
// reducer.test.js | |
describe('Login Reducers', () => { | |
it('properly captures a dispatch to change authenticated state', () => { | |
expect(loginReducer(initialState, switchAuthenticatedFlag(true))) | |
.toEqual({ | |
authenticated: true, | |
authenticating: false, | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment