Giter VIP home page Giter VIP logo

Comments (11)

brigonzalez avatar brigonzalez commented on May 22, 2024 2

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.

acostalima avatar acostalima commented on May 22, 2024 2

@brigonzalez jestjs/jest#6672

from jest-extended.

acostalima avatar acostalima commented on May 22, 2024 1

@benjaminkay93 not yet, but I will have some time tomorrow. Thanks for the reminder too! ๐Ÿ™

from jest-extended.

mattphillips avatar mattphillips commented on May 22, 2024

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.

acostalima avatar acostalima commented on May 22, 2024

@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.

benjaminkay93 avatar benjaminkay93 commented on May 22, 2024

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.

acostalima avatar acostalima commented on May 22, 2024

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.

benjaminkay93 avatar benjaminkay93 commented on May 22, 2024

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.

acostalima avatar acostalima commented on May 22, 2024

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.

acostalima avatar acostalima commented on May 22, 2024

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.

brigonzalez avatar brigonzalez commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.