question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] - Component Testing

See original GitHub issue

Hey guys, I am facing some issues trying to run some component tests. I am following the docs (https://playwright.dev/docs/test-components#how-to-get-started) and when running the first command, I can’t find any experimental module being installed, which I think is the one that needs to be used on the test file. Also, the npm run test-ct should be a script that executed “playwright test?”

I am not sure if the files mentioned in the docs should be added automatically to the project, but they are not , so I am creating them manually, after manually installing the “experimental-ct-react’” module.

Once I installed that and created both files, (.html and .js), I created my test class:

const { test, expect } = require('@playwright/experimental-ct-react');
const CookieBanner = require('../../../src/components/CookieBanner');
//import CookieBanner from '../../../src/components/CookieBanner/'

test.use({ viewport: { width: 500, height: 500 } });

test('event should work', async ({ mount }) => {
  let clicked = false;
  const component = await mount(<CookieBanner></CookieBanner>);

  await expect(component).toContainText('Submit');

  await component.click();

  expect(clicked).toBeTruthy();
});

When running playwright test, the issue is:

SyntaxError: Unexpected token ‘<’

The CookieBanner component is a .jsx file using export defaults.

Any help is appreciated. Thanks

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
imartinflorescommented, May 21, 2022

Thanks @rwoll , appreciated!

1reaction
rwollcommented, May 19, 2022

I am not sure if the files mentioned in the docs should be added automatically to the project, but they are not , so I am creating them manually

It should create the starter files automatically and install @playwright/experimental-ct-react automatically, so if it didn’t do that, something might be broken! Sorry about that!

Can you try again and (1) paste the output here, and (2) describe where you are running the command, where your package.json is (and generally the layout of your project)?

$ npm init playwright@latest -- --ct

Thanks for your patience as we start collecting feedback from the preview!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Component Testing? Techniques, Example Test Cases
Component testing is one of the black box test design techniques which is performed by QA Team. It's also referred to as module...
Read more >
What is Component Testing Or Module Testing (Learn With ...
What is Component Testing also called Module Testing in Software Testing: A component is the lowest unit of any application.
Read more >
What is Component testing? - Try QA
Component testing is a method where testing of each component in an application is done ... Component testing is also known as module...
Read more >
What is component testing ? - OneStopTesting
Automated Testing Testing Interview Questions & Answers, FAQs, Job Questions. ... Answer : Component testing, also known as unit, module and program testing...
Read more >
Difference between Component and Unit Testing
Component Testing is a type of software testing in which usability of each individual component is tested. Along with the usability test, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found