-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
Date API Proposal #117
Comments
Nice one @thiagodp I like these a lot! Fancy sending a PR for any of them? 😄 |
Hello @mattphillips , |
I believe the following shouldn't pass, since 0 value unix codes are common bugs This currently passes, but I believe should fail:
That or add matchers to test valid/recent unix, so we can avoid code like this to test timestamps were created on a resource:
|
Hi @CoreyKovalik, I think I disagree with you about Whether an application could not accept it in order to avoid some kind of problem, a programmer should document that with a test case. However, the (Jest-extended) library should allow it, since it is an acceptable value for a Date. |
@thiagodp Was thinking along the lines of the same thing. Would be nice to have a similar set of matchers for Unix timestamps |
@CoreyKovalik yes, it would be useful to have such matchers |
I'd like to propose a match for a timestamp being "within the last X ms". This is useful, for example, when testing that files like "createdAt" or "updatedAt" were properly updated within about the timestamp of the text. I'm currently using expect(Date.now() - object.updatedAt).toBeLessThan(10 * 1000); Proposed matcher: expect(object).toMatchObject({
// ...
updatedAt: expect.withinLast('10s'),
}); |
Anyone working on this? @thiagodp @mattphillips @CoreyKovalik ? If not, my work (@k4connect) is giving me some time to get these in, since they'd be useful for us. |
Hi All, |
I'm not working on any of these currently, but I can share what pattern I've been using as a solution in production tests. const now = Date.now()
const response = fooFunctionToTest()
const nowDelta = Date.now() - now
expect(response.timestamp).toBeGreaterThanOrEqual(now)
expect(response.timestamp).toBeLessThanOrEqual(now + nowDelta) It's been working for me for testing side effects in integration tests for values such as I secure this further with validating timestamps by extending Joi as well. const joiUnixTimestamp = (joi) => ({
name: 'unixTimestamp',
base: joi
.number()
.integer()
.min(0),
}) |
Hi { @RobertFischer , @hansal7014 , @CoreyKovalik }, I'm not working on any of these either. Suggetion (@hansal7014 ): |
I'll start working on these matchers. Thanks for the suggestions. |
Hi @thiagodp, |
Nice, @JamieMason. |
Feature Request
Description:
API for Date matchers. Some matchers are inspired by Jasmine Matchers.
Possible solution:
Jasmine-like matchers:
Additional matchers:
The text was updated successfully, but these errors were encountered: