Last active
March 27, 2021 22:51
-
-
Save andirkh/1a8a3718938bb60a1e6d1c3a4c2a6f83 to your computer and use it in GitHub Desktop.
Template for testing selectors
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
import { fromJS } from 'immutable'; | |
import { | |
... | |
} from '#src/containers/ContainersName/selectors'; | |
import { initialState } from '#src/containers/ContainersName/reducer'; | |
let mockReduxData; | |
jest.mock('reselect', () => ({ | |
createSelector: (fn, fn2) => { | |
return fn2(mockReduxData); | |
}, | |
})); | |
describe('ContainerName selectors', () => { | |
const testTable = [ | |
{ | |
name: 'selectorName should return true when the isVisible is true', | |
selector: selectorName, | |
data: { | |
isVisible: true, | |
}, | |
expected: true, | |
}, | |
]; | |
beforeEach(() => { | |
mockReduxData = undefined; | |
}); | |
testTable.forEach(({ name, data, expected, selector }) => { | |
it(name, () => { | |
mockReduxData = fromJS(data); | |
expect(selector()).toEqual(expected); | |
}); | |
}); | |
}); | |
describe('selectReducer', () => { | |
const reducerName = 'reducerName'; | |
const mockReducers = { | |
[reducerName]: initialState.toJS(), | |
}; | |
test('select selectReducer data in the reducers', () => { | |
const result = selectReducer()(fromJS(mockReducers)); | |
expect(result.toJS()).toEqual(mockReducers[reducerName]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment