Comments (3)
Huh, It works indeed. I was using a dummy component because I wanted to create some tests for a library that I'm implementing, so I had no idea about that.
As a Playwright newcomer, it wasn't intuitive while I was checking the documentation that I needed my components to be in a different file, though. If your team is receiving a PR to improve the documentation, I can maybe add a simple FAQ to clarify the situation, only if this is something that happens frequently and you'll think it's worth it.
In any case, this solves my issue, so I'm going to close this issue. Thanks, @mxschmitt!
from playwright.
Components which you are testing need to be in separate files. Modifying your code as per:
diff --git a/tests/MyComponent.tsx b/tests/MyComponent.tsx
new file mode 100644
index 0000000..aa454a4
--- /dev/null
+++ b/tests/MyComponent.tsx
@@ -0,0 +1,5 @@
+import React from 'react';
+
+export function MyComponent() {
+ return <p>hi</p>;
+}
\ No newline at end of file
diff --git a/tests/test.spec.tsx b/tests/test.spec.tsx
index 9b6e553..e6b2326 100644
--- a/tests/test.spec.tsx
+++ b/tests/test.spec.tsx
@@ -1,14 +1,10 @@
import { expect, test } from "@playwright/experimental-ct-react";
-import * as React from "react";
-
-function Page() {
- return <p>hi</p>;
-}
+import {MyComponent} from './MyComponent'
test.use({ viewport: { width: 500, height: 500 } });
test("do not pass", async ({ mount, page }) => {
- const component = await mount(<Page />);
+ const component = await mount(<MyComponent />);
await expect(component).toContainText("hi");
});
makes it work for me. See here on "How it works" under the hood.
from playwright.
If you are interested in making "Under the hood" more clear, feel free to send a PR, happy to review! Not sure if a separate FAQ Entry is needed here.
from playwright.
Related Issues (20)
- [Bug]: --only-changed flag and project dependencies HOT 1
- How to set --proxy-header in browser using playwright api HOT 3
- [Documentation]: document how to install playwright for pnpm HOT 3
- Rewrite `PWTEST_WATCH` as consumer of TestServer
- [Regression]: v1.45.1: Google login not working on the new version HOT 2
- [Bug]: Locator Handler Does Not Timeout HOT 1
- [Bug]: Intermittent "Object doesn't exist" error in playwright. HOT 1
- [Feature]: Allow ffmpeg binary path to be set HOT 1
- [Bug]: Playwright UI – Duplicate Test Name leads to odd behavior (disappearing tests, playwright hanging) HOT 1
- [Feature]: Make classes that claim to extend EventEmitter do so in their type definition
- [Bug] docs generates duplicate anchor for nested objects
- [Bug]: Unknown "Secureplaywright-set-cookie-separator" prefix inside Set-Cookie from api response breaks tests on webkit HOT 1
- Text explorer stuck on loading HOT 2
- [Bug]: UI Mode restart doesn't restart server with `reuseExistingServer: false`
- [Feature]: Add a warning message: Do not use TEMP or TMP environment variables, as they may cause browser installation failure. HOT 1
- [Bug]: Inconstant user agent setting HOT 1
- [Bug]: "should properly cancel Cross-Origin-Opener-Policy navigation" is failing
- [Bug]: playwright version 1.46 is having error when we use suite.allTests() function HOT 1
- [FIXED]: CDPSession WebAuthn Isn't Working HOT 1
- [Bug]: target is closed error when running multiple spec files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.