Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDate API Proposal #117
Date API Proposal #117
Comments
|
Nice one @thiagodp I like these a lot! Fancy sending a PR for any of them? |
|
Hello @mattphillips , |
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
Issue: jest-community#117
|
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. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Feature Request
Description:
API for Date matchers. Some matchers are inspired by Jasmine Matchers.
Possible solution:
Jasmine-like matchers:
Additional matchers: