Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using the config.rootDir jest.setMock doing something unexpected. #72

Closed
awei01 opened this issue Jun 12, 2014 · 3 comments
Closed

Comments

@awei01
Copy link

awei01 commented Jun 12, 2014

There seems to be an issue when using config.rootDir when mocking node_module(s).

folder structure

root
+ client
+ + app
+ + + foo.js
+ + + bar.js
+ + + __tests__
+ + + + test.js
+ node_modules
+ + lodash
+ + kew
+ package.json

root/package.json

{
    "jest":  {
        "rootDir": "client/app"
    }
}

root/client/app/tests/test.js:

'use strict';

describe('using config.rootDir', function() {

    it('has problems when mocking node_modules', function() {

                // lodash and kew have been installed with npm
        jest.setMock('lodash', 'lodash');
        jest.setMock('kew', 'kew');

        console.log(require('lodash'));
        console.log(require('kew'));

    }); 

    it('works when mocking my own modules', function() {

                // ../foo and ../bar are my own modules
        jest.setMock('../foo', 'foo');
        jest.setMock('../bar', 'bar');

        console.log(require('../foo'));
        console.log(require('../bar'));

    });

});

this yields:

Using Jest CLI v0.1.15
Found 1 matching tests...
 PASS  __tests__/baz-test.js (0.032s)
kew
kew
foo
bar
1 tests passed (1 total)
Run time: 0.86s

i was expecting:

Using Jest CLI v0.1.15
Found 1 matching tests...
 PASS  __tests__/baz-test.js (0.032s)
lodash
kew
foo
bar
1 tests passed (1 total)
Run time: 0.86s
@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@cpojer
Copy link
Member

cpojer commented Mar 3, 2016

I'm going to assume this issue has resolved itself in the last few minor versions.

@cpojer cpojer closed this as completed Mar 3, 2016
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants