Skip to content

Instantly share code, notes, and snippets.

@andirkh
Last active March 27, 2021 22:51
Show Gist options
  • Save andirkh/1a8a3718938bb60a1e6d1c3a4c2a6f83 to your computer and use it in GitHub Desktop.
Save andirkh/1a8a3718938bb60a1e6d1c3a4c2a6f83 to your computer and use it in GitHub Desktop.
Template for testing selectors
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