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

Mocking Backbone throws an error #59

Closed
maspwr opened this issue Jun 2, 2014 · 7 comments
Closed

Mocking Backbone throws an error #59

maspwr opened this issue Jun 2, 2014 · 7 comments

Comments

@maspwr
Copy link

maspwr commented Jun 2, 2014

Here's a very simple example showing how requiring Backbone will cause Jest to fail.

https://github.com/maspwr/backbone-jest/tree/master

TypeError: /Users/mark/projects/gitp/backbone-jest/__tests__/FailingTest.js: Cannot read property 'protocol' of undefined
  at Location.protocol (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/node_modules/jsdom/lib/jsdom/browser/location.js:18:36)
  at _getMetadata (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/moduleMocker.js:279:49)
  at _getMetadata (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/moduleMocker.js:286:23)
  at _getMetadata (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/moduleMocker.js:279:27)
  at _getMetadata (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/moduleMocker.js:279:27)
  at _getMetadata (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/moduleMocker.js:279:27)
  at Object.module.exports.getMetadata (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/moduleMocker.js:388:20)
  at Loader._generateMock (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:280:56)
  at Loader.requireMock (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:782:43)
  at Loader.requireModuleOrMock (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:897:17)
  at /Users/mark/projects/gitp/backbone-jest/__tests__/FailingTest.js:1:83
  at Object.runContentWithLocalBindings (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/utils.js:309:17)
  at Loader._execModule (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:243:9)
  at Loader.requireModule (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:879:10)
  at jasmineTestRunner (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/jasmineTestRunner/jasmineTestRunner.js:225:16)
  at /Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/TestRunner.js:369:12
  at _fulfilled (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/node_modules/q/q.js:760:13)
  at /Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/node_modules/q/q.js:574:44
  at flush (/Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/node_modules/q/q.js:108:17)
  at /Users/mark/projects/gitp/backbone-jest/node_modules/jest-cli/src/lib/FakeTimers.js:234:7
  at process._tickCallback (node.js:419:13)
@d1b1
Copy link

d1b1 commented Jun 23, 2014

+1

@chris-ramon
Copy link

Adding backbone path to unmockedModulePathPatterns fixes this.

package.json

{
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "unmockedModulePathPatterns": ["./node_modules/backbone"]
  },
  "dependencies": {
    "backbone": "^1.1.2",
    "jquery": "^2.1.1",
    "requirejs": "^2.1.14",
    "underscore": "^1.6.0"
  }
}

@tiagob
Copy link

tiagob commented Mar 26, 2015

+1

@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.

@nurrony
Copy link

nurrony commented Sep 28, 2015

@facebook-github-bot-4 What is the condition of this issue?

@cpojer
Copy link
Member

cpojer commented Oct 23, 2015

I'd recommend not mocking Backbone. It probably uses some meta programming that we can't mock properly.

@cpojer cpojer closed this as completed Oct 23, 2015
@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

6 participants