You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test("some date to be instance of Date",()=>{expect(global.someDateinstanceofDate).toBe(true);// the result is false});
To Reproduce
I made an example repository.
Steps to reproduce the behavior:
attach a Date to global inside a custom test environment
use instanceof on that variable in the the test
Note: In our case we instantiated a Knex client which we attached to global to instantiate it only once and destroy it only once. Once we ran a query where one entry was a date, but instanceof didn't work.
Expected behavior
global.someDate instanceof Date should be true
Link to repl or repo (highly encouraged)
git clone git@github.com:nikgraf/jest-bug-example.git
yarn
yarn test
Result:
➜ jest-example git:(master) yarn test
yarn run v1.10.1
$ jest
FAIL ./index.test.js
✓ adding two numbers (2ms)
✕ some date to be instance of Date (6ms)
● some date to be instance of Date
expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
8 | expect(new Date() instanceof Date).toBe(true);
9 | // NOTE this is an object containing methods like getMonth, but isn't a Date instance anymore > 10 | expect(global.someDate instanceof Date).toBe(true); | ^ 11 | }); at Object.toBe (index.test.js:10:43)Test Suites: 1 failed, 1 totalTests: 1 failed, 1 passed, 2 totalSnapshots: 0 totalTime: 0.328s, estimated 1sRan all test suites.error Command failed with exit code 1.info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Run npx envinfo --preset jest
Paste the results here:
npx envinfo --preset jest
npx: installed 1 in 2.133s
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Binaries:
Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
Yarn: 1.10.1 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
The text was updated successfully, but these errors were encountered:
This is expected - the global Date inside and outside of the sandbox is not the same.
You can work around it by doing this.global.someDate = new this.global.Date().
If you want to create something in the custom environment using the same globals, you need to execute it inside of the vm this.executeScript.
Also sorta dupe of #2549, although your use case (creating something outside of the sandbox and using it inside of it) is not really supported - it breaks the abstraction.
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.
🐛 Bug Report
A date created in the test environment and then attached to the global object is not an instance of
Date
.test environment
test
To Reproduce
I made an example repository.
Steps to reproduce the behavior:
Note: In our case we instantiated a Knex client which we attached to global to instantiate it only once and destroy it only once. Once we ran a query where one entry was a date, but instanceof didn't work.
Expected behavior
global.someDate instanceof Date
should be trueLink to repl or repo (highly encouraged)
Result:
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: