From 132ceff702b1a2826aa43c37f558c0de999ac47e Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 14 Jun 2024 01:10:35 +0200 Subject: [PATCH] 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 --- docs/src/test-components-js.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/test-components-js.md b/docs/src/test-components-js.md index 099dc2b362..cdb065347e 100644 --- a/docs/src/test-components-js.md +++ b/docs/src/test-components-js.md @@ -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 user’s perspective, it likely means the automated test has uncovered a genuine bug in your code.