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 have written integration-style tests before using Jest, where I made use of jest.fn() and jest.spyOn() to check if certain methods have been called, for example:
jest.spyOn(supabase.auth.signIn).mockImplementation(async()=>{return{authenticated: true};});// ...expect(supabase.auth.signIn).toHaveBeenCalledWith({email: 'me@example.com',password: '12345'// just for testing; don't ever use a password like this});
However, I have really struggled to find equivalents in Playwright. The closest thing I could find was the documentation on Mock APIs, but that's not quite the same thing because I may need to disable behavior (e.g. overriding window.location.reload() to be a no-op).
To work around this, I am currently using the sinon package, but it's not my favorite because I have to create many custom matchers (e.g. toHaveBeenCalled, toHaveBeenCalledOnce, etc.) to achieve the desired readability (as opposed to something like expect(stub.calledWith(1, 2, 3)).toBe(true).
So, are there equivalents to jest.fn() and jest.spyOn() in Playwright? If not, why is that?
Thanks in advance!
Caleb
The text was updated successfully, but these errors were encountered:
However, I have really struggled to find equivalents in Playwright. The closest thing I could find was the documentation on Mock APIs, but that's not quite the same thing because I may need to disable behavior (e.g. overriding window.location.reload() to be a no-op).
So, are there equivalents to jest.fn() and jest.spyOn() in Playwright? If not, why is that?
There is no direct support for this in playwright. Playwright's primary focus is on ent-to-end tests where testing with real browser implementation is considered more important. We've considered adding some support for writing mocks similar to sinon but decided not to do that as in the rare cases where you need to write such mocks you can usually use some good third-party library.
Hi,
I have written integration-style tests before using Jest, where I made use of
jest.fn()
andjest.spyOn()
to check if certain methods have been called, for example:However, I have really struggled to find equivalents in Playwright. The closest thing I could find was the documentation on Mock APIs, but that's not quite the same thing because I may need to disable behavior (e.g. overriding
window.location.reload()
to be a no-op).To work around this, I am currently using the sinon package, but it's not my favorite because I have to create many custom matchers (e.g.
toHaveBeenCalled
,toHaveBeenCalledOnce
, etc.) to achieve the desired readability (as opposed to something likeexpect(stub.calledWith(1, 2, 3)).toBe(true)
.So, are there equivalents to
jest.fn()
andjest.spyOn()
in Playwright? If not, why is that?Thanks in advance!
Caleb
The text was updated successfully, but these errors were encountered: