Skip to content

Instantly share code, notes, and snippets.

@itsanna
Created January 12, 2016 07:01
Show Gist options
  • Save itsanna/d182d224887dc05f1bb5 to your computer and use it in GitHub Desktop.
Save itsanna/d182d224887dc05f1bb5 to your computer and use it in GitHub Desktop.
Testing jobs reducer
import test from 'tape'
import jobsReducer from '../src/client/reducers/jobs'
const actualReducer = jobsReducer
const initialState = {
list: []
}
const initialState2 = {
list: [ { title: 'Actress' } ]
}
const action = {
type: 'ADD_JOB',
job: {
title: 'Web developer'
}
}
test('jobsReducer should handle ADD_JOB', function(assert) {
const newState = {
list: [ { title: 'Web developer' } ]
}
assert.plan(1)
assert.deepEqual(actualReducer(initialState, action), newState)
})
test('jobsReducer should return the initial state if state is not provided.', function(assert) {
assert.plan(1)
assert.deepEqual(actualReducer(undefined, {}), { list: [] })
})
test('jobsReducer should return the new state after applying the action to the previous state.', function(assert) {
const newState = {
list: [ { title: 'Actress'}, { title: 'Web developer' }]
}
assert.plan(1)
assert.deepEqual(actualReducer(initialState2, action), newState)
})
test('jobsReducer should not mutate the initial state.', function(assert) {
assert.plan(1)
assert.deepEqual(initialState, { list: [] })
})
test('jobsReducer should not mutate the action', function(assert) {
const newState = {
type: 'ADD_JOB',
job: {
title: 'Web developer'
}
}
assert.plan(1)
assert.deepEqual(action, newState)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment