Jest mocking too much?

236 views
Skip to first unread message

gior...@gmail.com

unread,
Nov 26, 2014, 5:26:50 AM11/26/14
to jes...@googlegroups.com
Hi,

I've been trying to use Jest to test React components written in CoffeeScript.

I used the provided CoffeeScript preprocessor example, just adding:
require('coffee-react/register');
so that it will accept CS + JSX syntax.

I then wrote my test:

jest.dontMock "#{__PATH__}/components/app.coffee"

describe 'App', ->
it 'is defined.', ->
App = require "#{__PATH__}/components/app.coffee"
expect(App).toBeDefined()

When I run jest, I get this error:

https://gist.github.com/kristoferjoseph/27c3e09eb1ec3443b5df

This error originates in myProject/node_modules/react/lib/ReactUpdates.js

var CallbackQueue = require("./CallbackQueue");
...
var asapCallbackQueue = CallbackQueue.getPooled();

While the function referred to in the backtrace is jest-cli/src/lib/moduleMocker.js.

So my impression here is that Jest is mocking CallbackQueue while it shouldn't.

What can I do in order to make my test run?

Thanks


pietro

mat...@gmail.com

unread,
Dec 1, 2014, 3:57:12 AM12/1/14
to jes...@googlegroups.com, gior...@gmail.com
Hi,
There's a bug in jest - best solution right now is to use "require.requireActual('module.js')" instead of jest.dontMock('module.js') + require('module.js').

require.requireActual will include the actual file instead of (auto)mocking it.

Best regards
Mateusz

gior...@gmail.com

unread,
Dec 1, 2014, 4:00:44 AM12/1/14
to jes...@googlegroups.com, mat...@gmail.com
Hi Mateusz,

Thank you, require.requireActual does the trick.


pietro
Reply all
Reply to author
Forward
0 new messages