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.

[Feature] component testing mount result

See original GitHub issue

Can the update and the unmount functions be added? This is useful for Vue, React and Svelte:

test('update props', ({ mount }) => {
  const component = await mount(Component, {
    props: { name: 'test' }
  });
  await component.update({ props: { name: 'test2' }});
  await expect(component).toHaveText('test2');
})
test('display a pending changes conformation', ({ mount }) => {
  const component = await mount(Component);
  await component.unmount();
  await expect(component.locator('#conformation-dialog')).toBeVisible();
})

TODO

  • update Svelte
  • update Solid
  • update React
  • update Vue
  • update Vue2
  • unmount Svelte
  • unmount Solid
  • unmount React
  • unmount Vue
  • unmount Vue2

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pavelfeldmancommented, Jul 29, 2022

We now have feature requests for the following functions and i think a few more will follow. Assuming it will be a breaking change, why not release it sooner rather than later?

We have until v1.25 branch point to make this decision. I agree with your points, we can put those calls on the Locator subclass. The unfortunate bit is that they might end up being different for each framework, but I guess we can live with it. Do you want to send a patch that does it?

1reaction
sand4rtcommented, Oct 11, 2022

Have you taken into account that the update will not automatically be type safe as well if i follow the current implementation of unmount?

test('work', ({ mount, update }) => {
  const component = mount<Props>(Component, { 
    props: { title: 'test' }
  })
  
  update<Props>(component, { props: { title: 'test' }}) // Must specifically specify the type here
})

instead of

test('work', ({ mount }) => {
  const component = mount<Props>(Component, { 
    props: { title: 'test' }
  })
  
  component.update({ props: { title: 'test' }}) // Reuse of the same type defined in mount<Props>()
})

In addition, Testing Library, Vue Test Utils and partially Cypress component testing are using the same API. If you decide to use the same API as well, context switching and the migration to Playwright will becomes easier.

We now have feature requests for the following functions and i think a few more will follow. Assuming it will be a breaking change, why not release it sooner rather than later?

component.unmount()
component.update()
component.emitted() // if feature request gets accepted

Arguably, but a minor inconvenience is that you will have some line breaks if we have many function props, making the code more verbose in some situtations…

test('some test description', ({ 
  page,
  mount,
  update,
  unmount
}) => {
   // arrange, act, expect
})

Maybe i’m nitpicking here, but would like to know what you think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress Component Testing
Our Test Runner is browser-based, allowing you to test not only your component's functionality but also styles and appearance. You can visually see...
Read more >
Testing React components with Cypress - CircleCI
This test suite first mounts the component with the cy.mount() command. It then checks to see if the input field has a placeholder...
Read more >
How to perform Component Testing using Cypress
Step 1: Create a sample react application​​ The component testing needs the application code to be present locally on the machine. Component ......
Read more >
Getting started with Playwright component testing
By default, the component tests will be executed in a headless mode without opening the Chromium, Webkit, and Firefox browsers. Add the -- ......
Read more >
JavaScript testing #3. Testing props, the mount function and ...
Tests that include using snapshots are quite useful. During such tests, the component is rendered and a snapshot of it is created. It...
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