Skip to content
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

Test against "any value of given type" #81

Closed
soanvig opened this issue Jul 3, 2023 · 2 comments
Closed

Test against "any value of given type" #81

soanvig opened this issue Jul 3, 2023 · 2 comments

Comments

@soanvig
Copy link

soanvig commented Jul 3, 2023

Hello!

My usecase is Ava's deepEqual function. In particular, I have some nested object of some sort. I'm not interested in the value of the values, but in their type. Is it possible to have something like Jest's expect.any(Boolean) for example? Or any dynamic matcher for a value?

Let say I want to check if:

{
   foo: ['a', 'b', 'c'],
   bar: {
      cat: new Cat(),
   }
}

is equal to

{
   foo: [String, String, String],
   bar: {
     cat: Cat
   }
}

That is: I'm more interested in the structure, rather than actual values (for example they are generated randomly).

@novemberborn
Copy link
Member

Architecturally Concordance is extensible, though AVA does not expose those hooks. That said, it's meant for use cases like comparing a Timestamp from say the Firestore SDK against a Date. It's not sufficient for your use case.

A technique I've used previously when snapshotting timestamps is to map it to a "yes this is a timestamp" string. You could do something like:

t.deepEqual(structure({
   foo: ['a', 'b', 'c'],
   bar: {
      cat: new Cat(),
   }
}), {
   foo: ['String', 'String', 'String'],
   bar: {
     cat: 'Cat'
   }
})

Where structure() does some deep mapping to the constructor name.

Structural comparisons would be an interesting addition but Concordance needs modernizing first.

@novemberborn novemberborn closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2023
@soanvig
Copy link
Author

soanvig commented Jul 10, 2023

Understood, thanks for the idea for the solution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants