question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest matchers don't allow use of jest submatchers for input object filtering

See original GitHub issue

Checklist

  • I have read Caveats documentation and didn’t find a solution for this problem there.

Bug description

The Jest matchers added here still use the sinon call matching logic here so jest submatchers don’t work. For example, I would expect this code to work:

expect(mock).toHaveReceivedCommandWith(QueryCommand, {
    TableName: expect.stringMatching(/^foo/)
});

Instead I get the following error:

Error: Expected DynamoDBDocumentClient to receive "QueryCommand" with {"TableName": StringMatching /^foo-/}
DynamoDBDocumentClient received "QueryCommand" 0 times
Calls:

  1. QueryCommand: {"ExpressionAttributeValues": {":guid": "guid"}, "KeyConditionExpression": "id = :guid", "Limit": 1, "ScanIndexForward": false, "TableName": "foo-undefined"}

Environment

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
m-radzikowskicommented, Jun 17, 2022

Thank you, I will check what’s the standard way of achieving this with custom Jest matchers and make an update.

1reaction
m-radzikowskicommented, Aug 22, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Matchers
Using Matchers. Jest uses "matchers" to let you test values in different ways. This document will introduce some commonly used matchers.
Read more >
The hidden power of Jest matchers | by Boris - Medium
1. Match calls with function in arguments. Imagine, that you need to test that some API method was called properly. When all method...
Read more >
Jest Array/Object partial match with objectContaining and ...
It's possible to do partial matches on Arrays and Objects in Jest using expect.objectContaining and expect.arrayContaining .</
Read more >
Add matcher to assert object keys · Issue #2143
Add a matcher to assert a given object keys exists. I've read the docs and didn't find any matcher for this. Something with...
Read more >
Jest: expect object not to have property - javascript
objectContaining() . This approach works fine but has one unfortunate edge case: It matches when the property exists, but is undefined or null...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found