Conversation
| globalObject.setImmediate = global.setImmediate; | ||
| globalObject.clearImmediate = global.clearImmediate; | ||
|
|
||
| addInstanceOfAlias(globalObject.Error, Error); |
There was a problem hiding this comment.
We should probably have some sort of blacklist and just loop all globals, rather than patching them in as people report bugs.
| }); | ||
|
|
||
| test('Array', () => { | ||
| expect([]).toBeInstanceOf(Array); |
There was a problem hiding this comment.
this assertion passes without change in jest...
There was a problem hiding this comment.
Does it make sense to test it in jsdom environment too?
There was a problem hiding this comment.
Too bad it's not supported as a flag, but yeah, I can run the tests in both envs
|
This seems to have broken node assert support... I'll see if I can take a look at it later this coming week. Help appreciated! |
| */ | ||
| 'use strict'; | ||
|
|
||
| export default function addInstanceOfAlias(target: Object, alias: Object) { |
There was a problem hiding this comment.
I don't know if alias is a good name. I only know alias in terms of giving things a different name but this is setting a different constructor. How about addInstanceOfObject or addInstanceOfConstructor or addInstanceParent or similar?
|
This is really super cool. Didn't know this feature in JS. TIL. |
|
@SimenB thanks for picking this up, sorry I never got around to finishing it |
|
@suchipi Thanks for pointing Btw, do you have any ideas about why this |
|
Can we use duck-typing in that assertion? |
|
I had a hope that |
|
I'm not sure why that's failing; before merging, it'd be good to verify the same issue doesn't occur in user code when using AssertionError |
c9a7b57 to
5cae4b3
Compare
|
Tried a rebase. Seems like the issue here is that all |
|
Is there any progress on this? I just ran into the same issue and it's really annoying. |
|
Is there anything that I can do to help move this along? I just spent 2 hours trying to track down why parsing the "Set-Cookie" header was not working only on tests. |
|
You can play with it and see if you can get the tests to pass. I can give it a quick rebase first, though 🙂 All help welcome! This is probably the biggest pain point I have with Jest, and a huge gotcha |
e4db645 to
8c16548
Compare
|
|
||
| if (error instanceof ExpectationFailed) { | ||
| return; | ||
| if (error && error.code === 'ERR_ASSERTION') { |
There was a problem hiding this comment.
not happy with this. The conditional itself is fine (probably better than instanceof), but this shouldn't be a necessary change
|
@SimenB FWIW, I tried Jest with this PR and it did not solve the bug. I'm using superagent, and the multiple set-cookie headers on a response are still returned concatenated instead of as separate elements in an array, as it does outside Jest. I linked |
|
Can you share your reproduction? I can add it as a test case 🙂 |
|
@SimenB This is one from the other ticket: This is fixed by However, this also does not fix my problem. I'm trying to find a small repro script but I've just noticed that in node 10 the problem does not happen, only in 8, so I'm less motivated now. :) |
|
I've noticed that in Node 10 several |
|
I just confirmed that the problem is on https://github.com/nodejs/node/blob/v8.x/lib/_http_outgoing.js#L313.
This check is not fixed even when aliasing Array with this PR. |
ce6b56d to
4309d7a
Compare
|
@edevil that's fixed in newer versions of Node, thankfully 🙂 (as you mention) If we can get this working for node 10, I'm perfectly fine with that (although it would be great if we could find a solution that works for all supported versions of node) |
|
I was trying to extract this to local jest environment, and found a bug.
Try running this: I've fixed this locally using |
|
Guys, this seems to be abandoned, but the fix is really needed to be able to (integration-) test rest apps, with e.g. |
|
FYI I found an instance of (pun not intended) this problem in koajs/koa#1466. |
|
You were asking for more tests. I collected a bunch here: SingleContextNodeEnvironment.test.ts Most of these tests fail with standard Jest but all work when using jest-environment-node-single-context Some of the tests may look very constructed but they simulate problems happening for real when working with types returned by Node APIs. I just had to be creative for these tests to get the various datatypes directly from Node. |
|
Hah wow, almost 3.5 years old this PR 🙈 Thanks a bunch @kayahr! I'll rebase this and add those. I have zero recollection of the state of this PR, but let's see where it's at. I need a screenshot to remember the times we supported node 6, tho! 😀 |
4309d7a to
ca75368
Compare
|
@mcheshkov I don't follow your example. Running your code in plain Node logs out |
|
This PR is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
|
This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |

Summary
This is a rebase of @suchipi's https://github.com/suchipi/jest/tree/instanceof_overrides with added tests.
I added the two small reproductions from #2549 for
Error, but I'd love to get small examples of other globals breaking (Object,Array,Buffer,Symbolcomes to mind). Can anyone provide those?Fixes #2549.
Test plan
Tests added (but I want more of them).