Skip to content

Instantly share code, notes, and snippets.

@tlaitinen
Created March 21, 2018 13:03
Show Gist options
  • Select an option

  • Save tlaitinen/2917636e0a9be1e0149fef153e7ce142 to your computer and use it in GitHub Desktop.

Select an option

Save tlaitinen/2917636e0a9be1e0149fef153e7ce142 to your computer and use it in GitHub Desktop.
import {actions, reducer} from './ui';
describe('ui actions', () => {
it('should create an action to set loading state', () => {
expect(actions.setLoading(true)).toEqual({
type: 'UI_SET_LOADING',
payload: true
});
});
it('should create an action to show modal', () => {
expect(actions.showModal({type:'dummy'})).toEqual({
type: 'UI_SHOW_MODAL',
payload: {type:'dummy'}
});
});
it('should create an action to hide modal', () => {
expect(actions.hideModal()).toEqual({
type: 'UI_HIDE_MODAL'
});
});
});
describe('ui reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual({
loading: true,
modals: []
});
});
it('should handle UI_SET_LOADING', () => {
expect(reducer(undefined, actions.setLoading(false))).toEqual({
loading: false,
modals: []
});
});
it('should handle UI_SHOW_MODAL', () => {
expect(
reducer(
{
loading:false,
modals:[{type:'dummy'}]
},
actions.showModal({type:'dummy'})
)
).toEqual({
loading: false,
modals: [{type:'dummy'}, {type:'dummy'}]
});
});
it('should handle UI_HIDE_MODAL', () => {
expect(
reducer(
{
loading:false,
modals: [{type:'dummy'}, {type:'dummy'}]
},
actions.hideModal()
)
).toEqual({
loading: false,
modals: [{type:'dummy'}]
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment