GithubHelp home page GithubHelp logo

Comments (3)

ccheever avatar ccheever commented on April 26, 2024

I've also run into this problem with a different module (not React). It's really confusing and unclear how to fix it.

ccheever@charless-mbp:~/projects/crayon$npm test

> [email protected] test /Users/ccheever/projects/crayon
> jest

Found 1 matching tests...
 FAIL  __tests__/crayon-test.coffee (0.022s)
● crayon › it Can be called like `crayon.red`
  - TypeError: /Users/ccheever/projects/crayon/crayon.js: Cannot read property 'ref' of null

from jest.

jeffmo avatar jeffmo commented on April 26, 2024

I just committed 3e5ddee (and published v0.1.15) which should make the module mocker more accurately pass through undefined and null exports values to the mocked version of the exports.

I also considered making jest throw with an error that suggests that, when undefined is encountered as an exports object, you should refer to this issue as it's likely that you're doing something like:

var createClass = require('createClass');
module.exports = createClass({ /*...*/ });

But I suppose this could false positive in the extremely rare case where someone, for some reason, intentionally (or non-erroneously) set their exports object to undefined...in which case the error message could be even more misleading.

I'm not necessarily unwilling to do this -- but I do think errors of this type should surface a more debuggable stack trace now with error messages more along the lines of TypeError: undefined is not a function. I do wonder if this will lead to people finding the source of the problem in a more reasonable way.

If this continues to be a source of pain and we keep getting questions about this, I'm willing to re-consider short-circuiting intentional module.exports = undefined scenarios in favor of a detailed explanation of why you might need to unmock something.

from jest.

github-actions avatar github-actions commented on April 26, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

from jest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.