question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

3.0.0: Tests for selectors failing

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
maxmantzcommented, Apr 14, 2016

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 👍

1reaction
mxstbrcommented, Apr 14, 2016

Awesome, glad to hear it worked out – sorry for all the struggles!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit tests fail in Laravel after update to 3.0.0 #5507 - GitHub
I'm trying to create a unit test for some basic code in Laravel 5.8. Tests fail, unfortunately. At first, the Class 'Codeception\TestCase\Test' ...
Read more >
Failure in qa:selectors on GitLab Security (#374556) · Issues
qa:selectors job is failing on GitLab Security: $ bundle exec bin/qa Test::Sanity::Selectors bundler: failed to load command: bin/qa ...
Read more >
java - TestEngine with ID 'junit-jupiter' failed to discover tests
java - TestEngine with ID 'junit-jupiter' failed to discover tests - Caused by: org. junit. platform.
Read more >
TestCafe Studio v1.3.0 - A New Way to Work with Selectors
A test will not fail when you refactor HTML or implement new behavior in JavaScript. Tests do not depend on page styles. You...
Read more >
ember-test-selectors | Yarn - Package Manager
Removes attributes starting with data-test- from HTML tags and component/helper invocations in your templates for production builds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found