How to assert object with a field of a given type?
Hi, I'm writing an integration test that needs to assert an object response, where the ID field can be of type string:
The
expect.any(String)
line doesn't work because that syntax is from Jest: https://jestjs.io/docs/expect#expectanyconstructor
Is there any way to do this in Deno?2 Replies
I'm trying to assert that the
data
object has an id
field of type String
, while also asserting the remaining fields with assertObjectMatch
I couldn't find anything similar to Jest's expect.any(String)
in the Deno testing docsBased on the documentation, Deno's
assertObjectMatch
function checks if an object matches a subset of the properties of another object. However, it doesn't provide a way to check the type of a property. It only checks if the properties and their values match.
Here's an example of how assertObjectMatch
is used:
In this case, it checks if the object { foo: true, bar: false }
has a property foo
with a value of true
.
To check the type of a property in an object, you might need to write a separate assertion. For example:
In this example, assertObjectMatch
is used to check the structure of the object, and assert
is used to check the type of the id
property. Please note that this information is not explicitly stated in the documentation, and this is a general advice based on the available methods in Deno's standard library.