-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: "Received: serializes to the same string" when using toStrictEqual
with fs.readdirSync
#11923
Comments
I assume this is due to #2549. If you add console.log('dirs1 instance', dirs1 instanceof Array);
console.log('dirs2 instance', dirs2 instanceof Array); to your test, only the first logs You can work around it by using That said, I think |
Can't think of a "symptomatic" fix for this without some kind of fix for #2549 |
Could do an |
While If I run this code instead: const fs = require(`fs`);
test(`fun?`, () => {
const dirs1 = Array.from(fs.readdirSync(__dirname));
const class1 = dirs1.__proto__.constructor;
const dirs2 = fs.readdirSync(__dirname);
const class2 = dirs2.__proto__.constructor;
expect(class1.name).toBe(`Array`);
expect(class2.name).toBe(`Array`);
expect(class1).toBe(class2);
}); I get:
If I also throw in a console log for those classes using: console.log(class1.toString());
console.log(class2.toString()); we get:
So that might be something to use for an underlying fix: if the |
I got a similar issue, stemming from a row returned by sqlite3. Converting the non-array to something with console.log("rows instance", rows instanceof Array); // -> rows instance false
console.log("rows instance", [...rows] instanceof Array); // -> rows instance true
expect([...rows]).toStrictEqual([
{
category: "pasta",
description: "Spaghetti cabonara",
rating: 5,
},
]); /* ->
Expected: [{"category": "pasta", "description": "Spaghetti cabonara", "rating": 5}]
Received: serializes to the same string
*/ |
I'm encountering this with just plain strings.
My data structure is just as above, and I'm doing Changing to use |
@CMCDragonkai you're going to have to show a minimal reproducible example in that case. Just showing the data structure isn't quite enough for folks to understand what code needs to be in place for the bug to surface. |
Yea it's strange, reproducible code wise, it's literally just comparing that structure I posted above. But I suspect comparing that structure in a code snippet won't work. There's something strange about the testing environment. But at the same time, this kind of error: |
the reason I asked is because "it depends on what's actually going wrong", so without minimal reproducible code, it's borderline impossible to tell. You may want to start a new issue instead, with the same kind of explanation that this one started with, showing enough code and instructions on what to do in order to reproduce the problem. In general, the error means "as far as I can tell these two things are not the same" which will happen not just on key or value disagreement, but also type. JS lets things "act like" other things, even if they aren't the same kind of thing. |
Hey guys - I'm actually finding a similar problem. However, the 'minimum' reproducible code isn't going to be very minimal: the objects involved are being affected by so many different jest plugins at this point that even my intelli-sense isn't keeping track of what's involved. I thought I'd mention it though so there's some extra evidence of the bug. The problem was resolved for me by JSON.stringify-ing my expected and actual result, but this isn't optimal obviously |
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. |
Version
27.2.2
Steps to reproduce
Create an empty dir, run
npm init
follwed bynpm install jest
and create a filetest.js
with content:Then run this with
npx jest test.js
Expected behavior
Given that
readdirSync
returns an array already, we'd expect both tests to pass. If fact, we'd look at the first test and go "why on earth use Array.from on something that's already an array?"Actual behavior
Additional context
I have no idea what's going on here, but I'm pretty sure it shouldn't be happening. That "received" kind of sounds like the test did pass, because what it received serialized to the same string that the expected value serializes to. That's exactly what we want. This should pass O_o
Environment
The text was updated successfully, but these errors were encountered: