docs(ct): faq how to access the component instance (#31305)

The question has been asked a few times:
https://github.com/microsoft/playwright/issues/16889,
https://github.com/microsoft/playwright/issues/22606 and I think more
people will encounter this
This commit is contained in:
Sander 2024-06-14 01:10:35 +02:00 committed by GitHub
parent a76e5824c0
commit 132ceff702
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -928,3 +928,7 @@ test('override initialState ', async ({ mount }) => {
await expect(component).toContainText('override initialState');
});
```
### How do I access the component's methods or its instance?
Accessing a component's internal methods or its instance within test code is neither recommended nor supported. Instead, focus on observing and interacting with the component from a user's perspective, typically by clicking or verifying if something is visible on the page. Tests become less fragile and more valuable when they avoid interacting with internal implementation details, such as the component instance or its methods. Keep in mind that if a test fails when run from a users perspective, it likely means the automated test has uncovered a genuine bug in your code.