-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
arrays are polluted #7700
Comments
use assert.deepStrictEqual(model.array.toObject(), array); |
@freewil I'm having the same kind of issues comparing Currently upgrading mongoose on a relatively large project and I have tests failing by the dozen because of that |
@freewil in thsi case getter is a better workaround |
@TrejGun your custom getter is the best way to work around this.
The only realistic possibility would be to support something like this: assert.deepStrictEqual(model.array, new mongoose.Types.Array(array)); Which we can do, but will require some substantial work. Would this work for your use case @TrejGun @ubald ? |
You can add this getter when compliling model something like
|
@TrejGun that's one way to do it, but then you always get arrays as plain arrays, so no Mongoose change tracking on |
oh i see
from
or its better to use |
Almost done, still need to switch |
Fix will be in 5.5.6. The answer is to do this: assert.deepStrictEqual(model.array, new mongoose.Types.Array(array)); Because two objects cannot be |
@vkarpov15 good to know, thanks |
Need to reopen this because it looks like this no longer works in Node.js 12: #7784 |
I opened up an issue with Node core about this: nodejs/node#27652 . We'll see what they come up with. |
This is IMO an ideal use case for proxies. That way it's possible to pretend to be a clean array while still being able to track changes.
The issue is only about loose equal comparison. If I'm not mistaken your fix is to use a symbol properties instead of string properties. That will still fail using the strict assertion. The loose assertion is actually deprecated and I recommend not to use it.
This would of course also be a possibility while it moves the complexity to the user to be aware that the returned type is not just an array. Using the proxy as proposed above would allow to hide all the internals so that the users do not have to worry about this anymore. |
Thanks for the feedback. I'm aware that Refactoring to use symbols was beneficial for internal readability, because so many objects in Mongoose have |
wow |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
unable to compare arrays using standard node's assert framework
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
model.array
should be pure array, no additional hidden fieldsWhat are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: 8.15.1
mongodb 4.0.6
mongoose: 5.0.0 - 5.4.20
The text was updated successfully, but these errors were encountered: