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

TypeError: timer.unref is not a function #1909

Closed
xjamundx opened this issue Oct 10, 2016 · 8 comments
Closed

TypeError: timer.unref is not a function #1909

xjamundx opened this issue Oct 10, 2016 · 8 comments

Comments

@xjamundx
Copy link

Do you want to request a feature or report a bug?

Bug, or just support request (sorry!)

What is the current behavior?

Lots of errors around TypeError: timer.unref is not a function when trying to run jest on my mocha tests.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test.

Yeah just do this

test.js

test('thing', () => {
   var timer = setInterval(() => {}, 1)
   timer.unref()
})

And then run it with jest somehow.

 FAIL  tests/test2.js
  ● thing

    TypeError: timer.unref is not a function
      at Object.<anonymous> (tests/test.js:3:10)
      at process._tickCallback (node.js:364:9)

What is the expected behavior?

Not FAIL.

It works fine when you run the code directly with node. Also here is the API for it:
https://nodejs.org/api/timers.html#timers_timeout_unref

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.

  • node 4.5
  • npm 3.10.8

Debug has basically the same output as above:

jest version = 16.0.1
test framework = jasmine2
config = {
  "testPathDirs": [
    "/Users/jamuferguson/dev/paypal/p2pnodeweb"
  ],
  "setupFiles": [
    "/Users/jamuferguson/dev/paypal/p2pnodeweb/node_modules/babel-polyfill/lib/index.js",
    "/Users/jamuferguson/dev/paypal/p2pnodeweb/tests/lib/setup-test-env-jest.js"
  ],
  "testRegex": "tests/test2.js",
  "testURL": "http://example.com",
  "testPathIgnorePatterns": [
    "/node_modules/",
    "/vendor",
    "/helpers/",
    "/fixtures/"
  ],
  "moduleNameMapper": [
    [
      "^.+\\.svg$",
      "/Users/jamuferguson/dev/paypal/p2pnodeweb/public/js/__mocks__/custom/file-mock.js"
    ]
  ],
  "coverageThreshold": {
    "global": {
      "branches": 29,
      "functions": 22,
      "lines": 32,
      "statements": 29
    }
  },
  "collectCoverageFrom": [
    "!public/js/{vendor,view,widgets,hooks,collection,model,lib}/**",
    "!public/js/{konami,bootstrap}.js"
  ],
  "coverageDirectory": "/Users/jamuferguson/dev/paypal/p2pnodeweb/coverage/react",
  "rootDir": "/Users/jamuferguson/dev/paypal/p2pnodeweb",
  "name": "-Users-jamuferguson-dev-paypal-p2pnodeweb",
  "testRunner": "/Users/jamuferguson/dev/paypal/p2pnodeweb/node_modules/jest-jasmine2/build/index.js",
  "scriptPreprocessor": "/Users/jamuferguson/dev/paypal/p2pnodeweb/node_modules/babel-jest/build/index.js",
  "usesBabelJest": true,
  "automock": false,
  "bail": false,
  "browser": false,
  "cacheDirectory": "/var/folders/9d/p3qfw0g94yz7qh3z9dr4btwm391xgk/T/jest",
  "clearMocks": false,
  "coveragePathIgnorePatterns": [
    "/node_modules/"
  ],
  "coverageReporters": [
    "json",
    "text",
    "lcov",
    "clover"
  ],
  "globals": {},
  "haste": {
    "providesModuleNodeModules": []
  },
  "mocksPattern": "__mocks__",
  "moduleDirectories": [
    "node_modules"
  ],
  "moduleFileExtensions": [
    "js",
    "json",
    "jsx",
    "node"
  ],
  "modulePathIgnorePatterns": [],
  "noStackTrace": false,
  "notify": false,
  "preset": null,
  "preprocessorIgnorePatterns": [
    "/node_modules/"
  ],
  "resetModules": false,
  "testEnvironment": "jest-environment-jsdom",
  "timers": "real",
  "useStderr": false,
  "verbose": null,
  "watch": false,
  "cache": true,
  "watchman": true,
  "testcheckOptions": {
    "times": 100,
    "maxSize": 200
  }
}
Determining test suites to run...watchman warning:  Recrawled this watch 1 times, most recently because:
/Users/jamuferguson/dev/paypal/p2pnodeweb: kFSEventStreamEventFlagUserDropped
To resolve, please review the information on
https://facebook.github.io/watchman/docs/troubleshooting.html#recrawl
To clear this warning, run:
`watchman watch-del /Users/jamuferguson/dev/paypal/p2pnodeweb ; watchman watch-project /Users/jamuferguson/dev/paypal/p2pnodeweb`

 FAIL  tests/test2.js
  ● thing

    TypeError: timer.unref is not a function

      at Object.<anonymous> (tests/test2.js:3:10)
      at process._tickCallback (node.js:364:9)

  ✕ thing (3ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        3.936s
Ran all test suites.
@xjamundx
Copy link
Author

xjamundx commented Oct 11, 2016

So far it seems my issue is related to the fact that the setInterval implementation being used is not the native node one, but instead one provided by JSDom.

console.log(setInterval.toString()) // inside the test

matches https://github.com/tmpvar/jsdom/blob/a6acac4e9dec4f859fff22676fb4e9eaa9139787/lib/jsdom/browser/Window.js#L176

@xjamundx
Copy link
Author

xjamundx commented Oct 11, 2016

The solution is to use "testEnvironment": "node"

http://facebook.github.io/jest/docs/configuration.html#testenvironment-string

danielbayerlein added a commit to bugthesystem/hapijs-status-monitor that referenced this issue Nov 18, 2016
yami-beta added a commit to yami-beta/license-info-webpack-plugin that referenced this issue May 25, 2018
thierrymichel added a commit to epicagency/snitchy that referenced this issue Dec 1, 2018
yami-beta added a commit to yami-beta/license-info-webpack-plugin that referenced this issue Jan 1, 2019
kenvunz pushed a commit to gladeye/bento that referenced this issue Feb 3, 2019
glebtv added a commit to glebtv/sass-resources-loader that referenced this issue Jul 5, 2019
justin808 pushed a commit to shakacode/sass-resources-loader that referenced this issue Jul 15, 2019
…t warnings (#95)

* update to webpack 4
* use node as test environment jestjs/jest#1909
* fix remaining eslint problems
@alejo4373
Copy link

I got here by googling this.pruneTimer.unref is not a function. I thought I was not gonna get any results but this issue was at the top. It was not an exact match yet I still decided to read it. The error was coming from connect-pg-simple. I'm using connect-pg-simple for session storage on an express app.

Setting "testEnvironment": "node" as mentioned here works.

Just leaving this here for anyone else that might need it.

@NathTech
Copy link

NathTech commented Feb 23, 2021

I'm also getting the TypeError: this.timerId.unref is not a function when testing React elements interacting with Firebase Firestore.

Changing the testEnvironment to node fixes the above error, but then obviously none of the useful dom implementations are available from jsdom :-/

Does anyone have any thoughts when you are trying to test React elements that need the jsdom environment for things like localStorage?

@matt-kinton
Copy link

@NathTech I'm getting the same issue, trying to write some integration tests wish Jest + JSDOM + React + Emulators but I'm blocked testing anything that uses firestore

@naourass
Copy link

naourass commented Mar 4, 2021

Have the same warning when using Jest to test React + Firestore.

@matt-kinton
Copy link

matt-kinton commented Mar 4, 2021

Yes! someone else! Please comment on the issues I raised in other repositories for visibility :)

Here firebase/firebase-js-sdk#4552 and facebook/create-react-app#10626.

Found any workarounds @naourass?

@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 10, 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

5 participants