Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.