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
When this feature gets implemented:
Playwright would provide a generic callback mock that can be passed into components which then later can be asserted using appropriate assertions from expect
// from thetest('event should work',async({ mount })=>{letclicked=false;constcomponent=awaitmount(<Buttontitle="Submit"onClick={()=>{clicked=true}}></Button>);awaitcomponent.click();expect(clicked).toBeTruthy();});
What it could look like after implementation:
test('event should work',async({ mount })=>{constmock=fn()// fn is provided by playwrightconstcomponent=awaitmount(<Buttontitle="Submit"onClick={mock}></Button>);awaitcomponent.click();awaitexpect(mock).toHaveBeenCalledTimes(1);});
Other assertions could be: .toHaveBeenCalled .toHaveBeenCalledWith
Motivation
The primary motivation is ease of use.
Testing single components also involves how they react to user interaction, and how they would pass information to their parents.
As in the example docs example firing a callback when a component is clicked.
Since stuff like this is common to test i would see it beneficial to have a common way to do it.
When a user implements these themself mistakes can happen leading to flaky tests.
Taking the docs example as a reference, since the assertion is not wrapped into expect.poll the test might be flaky because as far as i know the React event is not guaranteed fired before the assertion.
A native feature could lower the risk of this happen.
I think having these assertions would make migrating from other component test frameworks a lot easier since a lot of frameworks offer these kinds of assertions and having a native alternative could lower the entry barrier to migrate.
Overall i think it would greatly improve usability and improve ease of use writing component tests with playwright-ct.
The text was updated successfully, but these errors were encountered:
It is likely to grow our expect API surface twice or so. If you can use third party mocking library (sinon?), that would work. Otherwise we would need to consider a better interop with jest.fn or to repeat it in our api, which is suboptimal.
馃殌 Feature Request
When this feature gets implemented:
Playwright would provide a generic callback mock that can be passed into components which then later can be asserted using appropriate assertions from
expect
Example
Status Quo:
From the docs
What it could look like after implementation:
Other assertions could be:
.toHaveBeenCalled
.toHaveBeenCalledWith
Motivation
The primary motivation is ease of use.
Testing single components also involves how they react to user interaction, and how they would pass information to their parents.
As in the example docs example firing a callback when a component is clicked.
Since stuff like this is common to test i would see it beneficial to have a common way to do it.
When a user implements these themself mistakes can happen leading to flaky tests.
Taking the docs example as a reference, since the assertion is not wrapped into
expect.poll
the test might be flaky because as far as i know the React event is not guaranteed fired before the assertion.A native feature could lower the risk of this happen.
I think having these assertions would make migrating from other component test frameworks a lot easier since a lot of frameworks offer these kinds of assertions and having a native alternative could lower the entry barrier to migrate.
Overall i think it would greatly improve usability and improve ease of use writing component tests with playwright-ct.
The text was updated successfully, but these errors were encountered: