Comments (4)
Maybe you could reduce the strictness level of your assertion like with
toMatchObject
, it should pass even if it is a proxy.
🙏 @Sytten thank you! toMatchObject()
works here, and is probably what I should have been using all along. I am going to close this issue since that is the more idiomatic expectation.
from jest-mock-extended.
It was most likely a side effect pf #60
Since this was introduced to fix a bug I expect it will stay that way.
Strict equality on JS objects that are not primitives is always brittle at best.
I would suggest either creating an operator for jest for dates or just comparing the timestamp that underlines the date.
from jest-mock-extended.
I appreciate your comment @Sytten and thank you to all the contributors. This is a useful package.
If I was just testing the value of createdAt
I could compare the underlying timestamp, but in this case I want to assert on the structure of this query object (Sequelize) that I'm building up. I don't even know how to write an expectation that this part of the object is a proxied Date that matches the expected timestamp.
either creating an operator for jest for dates
I'm not sure what this would look like, can you think of something similar to base that on?
I looked at #60 and I think I may have experienced that bug a few months ago and just lived without the assertion I was trying to make because I couldn't understand the cause at the time. If this new issue isn't a bug, it at least feels like a limitation and it is surprising to me, as a user (the surprise is that I set createdAt
as a Date
, but it was converted into a Proxy
.)
Is there any way to more generally have a Proxy for a Date pass an equality expectation with a Date? If not, maybe I just need to embrace the workaround of setting createdAt: mock<Date>()
in this case.
from jest-mock-extended.
Maybe you could reduce the strictness level of your assertion like with toMatchObject
, it should pass even if it is a proxy.
To me it is no surprising behaviour since it is within a mock
, otherwise you would need a spy or a partial mock (which are not a thing in this lib right now).
from jest-mock-extended.
Related Issues (20)
- Option to have mock methods throw by default HOT 2
- description field for Custom Matcher should be optional HOT 2
- Mocks evaluate to `undefined` when used with expect.anything() or expect.any()
- how to define overridable default mock implementation HOT 3
- Doesn't mock special fn in prisma package
- `.calledWith` ignores plain objects as its condition HOT 2
- Support for TypeScript 5.0 HOT 1
- Required to use calledWith when using TypeScript HOT 2
- Typescript error when using @jest/globals
- Doesn't work if injectGlobals is false HOT 2
- The captor function causes type errors when used with `calledWith`.
- How to deep-compare objects with `calledWith`? HOT 1
- Cannot set mock return value on `toString`
- TypeError: Jest: a transform must export a `process` function.
- How to mock an external package with deepMock HOT 1
- How to compare mock to an object with jest HOT 3
- Extreme slow processing of mocks that are created via the mock() function
- Add support for Jest v30
- Type 'DeepNullable<K>' does not satisfy the constraint 'WeakKey' HOT 3
- Capture arguments passed to method on mocked object
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-mock-extended.