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

Using dontMock() disables all mocking #64

Closed
codyhatch opened this issue Jun 5, 2014 · 2 comments
Closed

Using dontMock() disables all mocking #64

codyhatch opened this issue Jun 5, 2014 · 2 comments

Comments

@codyhatch
Copy link

This seems similar to #20 but significantly broader. Similar to the older issue, with the latest version of Jest on NPM (tagged v0.1.15), this fails:

describe('SomeTest', function() {
    it("requires underscore (unmocked) and jQuery (mocked)", function() {
        jest.dontMock('underscore');
        var _ = require('underscore');
        var $ = require('jquery');

        expect(_.mock).toBeUndefined();
        expect($.mock).toBeDefined();
    })
});
Found 1 matching tests...
 FAIL  test/client/bug-test.js (0.062s)
● SomeTest › it requires underscore (unmocked) and jQuery (mocked)
  - Expected undefined to be defined.
        at Spec.<anonymous> (/Users/cody/Coding/elephant_project/app/test/client/bug-test.js:9:24)
        at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
1 tests failed, 0 tests passed (1 total)
Run time: 1.003s

However, this works:

describe('SomeTest', function() {
    it("requires underscore (unmocked) and jQuery (mocked)", function() {
        jest.dontMock('underscore');
        var _ = require('underscore');
        jest.mock('jquery')
        var $ = require('jquery');

        expect(_.mock).toBeUndefined();
        expect($.mock).toBeDefined();
    })
});

HOWEVER, contrary to the initial bug report, this seems to be affecting more than just NPM modules. In fact, this works:

var App = require('../../src/client/code/app/app.js');

describe('test 1', function() {
  return it('should', function() {
    expect(App.mock).toBeDefined();
  });
});

But this fails:

jest.dontMock('jquery');

var App = require('../../src/client/code/app/app.js');

describe('test 1', function() {
  return it('should', function() {
    return expect(App.mock).toBeDefined();
  });
});

As does this:

jest.dontMock('../../src/client/code/app/app.js');

var $ = require('jquery');

describe('test 1', function() {
  return it('should', function() {
    return expect($.mock).toBeDefined();
  });
});

In short: Calling .dontMock() on an ANY module seems to disable mocking on ALL modules thereafter.

@codyhatch
Copy link
Author

Closing in favour of #66, which has a much clearer description of the issue.

@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

1 participant