Description
What is the problem this feature will solve?
Given for example a Date.now
in a nested object I would like be able to run deepEqual
on the object.
Such situation often happens if you are testing responses from APIs or something similar.
This obviously will throw an AssertionError:
assert.deepEqual({
a: 1,
b: Date.now()
}, {
a: 1,
b: 1728380577053,
});
What is the feature you are proposing to solve the problem?
One option would be to introduce an asymmetric matcher assert.any
that could dynamically check on the given type in the expected object.
Checking the type is often enough in such situation.
This would pass:
assert.deepEqual({
a: 1,
b: Date.now()
}, {
a: 1,
b: assert.any(Number),
});
Another option would be to let you define custom asymmetric matchers:
assert.deepEqual({
a: 1,
b: Date.now()
}, {
a: 1,
b: assert.asymetricMatcher((v) => typeof v === "Number"),
});
What alternatives have you considered?
I tried to use another assertion library which are capable of doing this: Vitest, unexpected.js, Jest
But this gives mangled output and I am not satisfied to bring in such big libraries for the sake of only doing asymmetric matching. Also I explain my tests in a documentation for other developers and I would like to use the Node built-in tools for simplicity.
Metadata
Assignees
Labels
Type
Projects
Status
Triaged
Activity