You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing a custom matcher for my own API response schema. I want to use jest's built-in assert functions inside my custom matcher so that I don't have to write my own test functions inside my custom matcher. Here is my code
expect.extend({toContainValidAPIResponseBody(received,argument){constpass=this.toMatchObject({data: expect.any(Array),errors: expect.any(Array),status: expect.any(String)});constmessage=()=>(`expected ${this.utils.printReceived(received)} to be a valid Farmer Backend API Response`);if(pass){return{
message,pass: true};}else{return{
message,pass: false};}}});
The problem is that this.toMatchObject is not a valid statement. Is there a way to access functions like toMatchObject inside a custom matcher?
The text was updated successfully, but these errors were encountered:
amirsaleem-kn
changed the title
How to access jest's custom assert functions in a custom matcher
How to access jest's assert functions in a custom matcher
Oct 5, 2020
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
💬 Question
I am writing a custom matcher for my own API response schema. I want to use jest's built-in assert functions inside my custom matcher so that I don't have to write my own test functions inside my custom matcher. Here is my code
The problem is that
this.toMatchObject
is not a valid statement. Is there a way to access functions liketoMatchObject
inside a custom matcher?The text was updated successfully, but these errors were encountered: