Comments (11)
You can reinstate timestamps and use nodeโs process.hrtime() to calculate milliseconds between another process.hrtime() call. Although, not sure how process.hrtime() really looks as a โtimestampโ since itโs using an arbitrary process to calculate a time difference.
Looks like convert-hrtime handles that conversion to milliseconds nicely.
from jest-extended.
from jest-extended.
@benjaminkay93 not yet, but I will have some time tomorrow. Thanks for the reminder too! ๐
from jest-extended.
Hey @acostalima #98 has now been published in v0.6.0.
This matcher is possible to make now, like #98 to work the mocks will need to be asynchronous to be ran in different contexts to generate different timestamps. That is something that will happen in user land. So we can just assume the test author is doing this and perform the comparisons on the timestamps ๐
If possible, I'd very much like to work on a PR for this. ๐
I'd be more than happy for you to send a PR for this, if you need any help just let me know ๐ as a place to start take a look at 966db3c
from jest-extended.
@mattphillips Great! I'll work on this ASAP.
Concerning the implementation, the behavior I'm actually looking for, at least in my specific use case, it to ensure the mock is called only after the specified milliseconds have elapsed. So, following the example I presented above:
- The 1st retry should only be called after 2000 milliseconds have elapsed since the first call
- The 2nd retry should only be called after 4000 milliseconds have elapsed since the 1st retry
Sounds good?
from jest-extended.
hey @acostalima, did you manage to do this? if not I am happy enough to raise a PR for this as it would be helpful for myself anyways.
from jest-extended.
I just learned Jest does not store timestamps of mock's invocations anymore ๐(jestjs/jest#5867). Without such information, I don't think we can implement this matcher anymore... do we?
from jest-extended.
Ahh I hadn't seen this ๐ข it explains the changes to toHaveBeenCalledBefore that have been merged in but not published here.
It might be worth asking for this to be revisited to reinstate the timestamps to enable this, I can see a legitimate use case for a matcher such as this. Without that, this wouldn't be possible from what I know of the .mock information. If we had both we could maintain support for the toHaveBeenCalledBefore matcher in jest 22 as well as jest 23 in the next release of jest-extended.
from jest-extended.
I guess we can ask. However, .timestamps
was explicitly removed in favor of .invocationCallOrder
(jestjs/jest#4402, jestjs/jest#5867) due to precision issues, but @brigonzalez was headed towards a possible solution (jestjs/jest#4402 (comment)).
from jest-extended.
Ok. I'll start a discussion in Jest's repo to get feedback. If we are good to go, let me know if you'd like to do the honors, @brigonzalez, and open the PR to reinstate the record of timestamps. Otherwise, I can try to do it myself. ๐
from jest-extended.
Sure thing! Let me know if weโve got the green light, or shoot me a link to the discussion!
from jest-extended.
Related Issues (20)
- Better clarify the difference between toIncludeAllMembers and toIncludeSameMembers in the documentation
- Vitest typings override instead of augmenting module HOT 26
- Feature Request: Support "export" package
- Number matches should not coerce non-numbers to numbers. HOT 1
- `toEqual` passes on non-equal arrays where trailing undefined HOT 1
- `toIncludeSameMembers` output is hard to understand HOT 2
- `toHaveBeenCalledExactlyOnceWith` expects an array of objects, when the object is passed as `args` HOT 6
- Current setup instructions for Vitest don't work for asymmetric matchers' typings HOT 9
- [Bug]: The second param of toHaveBeenCalledBefore/toHaveBeenCalledAfter has default value, but is not typed as optional HOT 1
- Declaration merging does not work without exporting the CustomMatchers interface. HOT 2
- `fail` does not work when testing code using a `try/catch`
- toBeInRange bug in implementation HOT 4
- value '...actual' is not correct for toHaveBeenCalledExactlyOnceWith fail case HOT 1
- TypeScript declarations are not working when used with @jest/globals
- Use jest-diff in toHaveBeenCalledWith matcher results
- Chore: Is there any plan to upgrade yarn to the latest? HOT 1
- `toContainOneOf([string1, string2, string3])` would be nice
- BUG: nested matcher printing "object Object"
- Feature Request: Array matcher diff
- Simplify typescript recommendations HOT 4
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-extended.