diff --git a/docs/src/test-components-js.md b/docs/src/test-components-js.md index 12d8b33f98c9a..edf3824248137 100644 --- a/docs/src/test-components-js.md +++ b/docs/src/test-components-js.md @@ -174,7 +174,7 @@ When Playwright Test is used to test web components, tests run in Node.js, while This however, is introducing a number of limitations: -- You can't pass complex live objects to your component. Only plain JavaScript objects and built-in types like strings, numbers, dates etc. can be passed. +- You can't pass complex live objects to your component. Only plain JavaScript objects and built-in types like strings, numbers, dates etc. can be passed. Class instances will lose their prototype methods during serialization — use plain objects or [test stories](#test-stories) instead. ```js test('this will work', async ({ mount }) => { @@ -184,6 +184,11 @@ test('this will work', async ({ mount }) => { test('this will not work', async ({ mount }) => { // `process` is a Node object, we can't pass it to the browser and expect it to work. const component = await mount(); + + // Class instances lose their prototype methods when serialized. + // Calling `user.greet()` in the component will fail. + class UserModel { greet() { return `Hello, ${this.name}`; } } + await mount(); }); ```