3.0.0: Tests for selectors failing
See original GitHub issueI have the following state structure:
const state = fromJS({
global: fromJS({
snackbar: fromJS({
open: false,
message: 'some message'
})
})
});
I have the following selectors set up:
globalSelector:
export default const () => (state) => state.get('global');
snackbarSelector:
const snackbarSelector = () => createSelector(
globalSelector(),
(globalState) => {
console.log('globalSelector', globalSelector());
const state = globalState.get('snackbar');
console.log('snackbarState', state);
return state;
}
);
export default snackbarSelector;
and the following test for the snackbar selector:
import snackbarSelector from '../snackbarSelector';
import { fromJS } from 'immutable';
import expect from 'expect';
const selector = snackbarSelector();
describe('snackbarSelector', () => {
it('selects the snackbar state', () => {
const snackbar = {
open: false,
message: 'some message',
};
const mockedState = fromJS({
global: {
snackbar,
},
});
expect(selector(mockedState)).toEqual(snackbar);
});
});
The selectors work as intended when i run the app, however during tests, the following error message appears:
Chrome 49.0.2623 (Windows 10 0.0.0) LOG: ‘globalSelector’, function (state) { … } Chrome 49.0.2623 (Windows 10 0.0.0) ERROR Uncaught TypeError: Cannot read property ‘get’ of undefined at C:/Projekte/react-boilerplate/internals/testing/test-bundler.js:138606 <- webpack:///app/selectors/snackbarSelector.js:9:933
the console.log() inside snackbarSelector still works (the first output). However when it tires to access the state parameter via globalState.get('snackbar'), the code fails. Do you know what could be causing this? I know that all of your tests for the sample app work fine. Is there maybe something in the test environment setup I’m missing?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (8 by maintainers)

Top Related StackOverflow Question
Final update: after cloning the repo again, this time under c:\ instead of my documents folder, and running in a NodeJS command prompt with admin rights, everything mysteriously started working. I don’t know why, but npm on Windows sometimes makes me want to pull my hair out. Thanks for your help 👍
Awesome, glad to hear it worked out – sorry for all the struggles!