Skip to content

Instantly share code, notes, and snippets.

@KTruong008
Created October 1, 2017 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KTruong008/91a932624e8463ab31bafaacbd75e63e to your computer and use it in GitHub Desktop.
Save KTruong008/91a932624e8463ab31bafaacbd75e63e to your computer and use it in GitHub Desktop.
// 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