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.

[ct]: sometimes SvelteComponent.$on() is not in sync

See original GitHub issue

In a regular scenario it seems that custom event is not dispatched in sync with the test execution and after searching in Playwright repo and Svelte repo, i don’t know how to understand this.

https://github.com/microsoft/playwright/blob/693ed9b19e03f7d29ef188e8b71d6f9485093c8b/packages/playwright-ct-svelte/registerSource.mjs#L104

The value of result in the test sometimes is null:

evidence-1

I need to do a trick and “await” for the result binding a global var inside the component:

evidence-2

¿await locator("...").click() is not really waiting to the callback finnish when is a well declared Promise? Here is the trick with global var. Previously, there is a dispatcher('end', result).

evidence-3

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, Oct 14, 2022

Not sure if possible but it would be great if we don’t have to think about awaiting at all. Maybe with a retry mechanism?

You can already achieve that with poll:

await expect.poll(() =>messages).toEqual(['clicked']);

Unfortunately there is no generic mechanism that would automatically wait for the desired effects of a user action. Closing this issue as there are several solutions for the problem.

1reaction
sand4rtcommented, Oct 14, 2022

Not sure if possible but it would be great if we don’t have to think about awaiting at all. Maybe with a retry mechanism? Made a simpler version of the problem:

// Button.svelte
<script lang="ts">
  import { createEventDispatcher } from "svelte";
  const dispatch = createEventDispatcher();

  async function handleClick() {
    await new Promise(r => setTimeout(r, 5000)); // sleep 5 seconds
    dispatch("click");
  }
</script>
 
<button on:click={handleClick}>Submit</button>
// tests.spec.ts
test('emit an async event when the button is clicked', async ({ mount }) => {
  const messages: string[] = []
  const component = await mount(Button, {
    on: {
      click: () => {
        messages.push('clicked')
      }
    }
  })
  await component.click();
  expect(messages).toEqual(['clicked']) // fails because we need to await handleClick
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not synchronized when directly accessing component props ...
1. <script> ; 2. import Component from './Component.svelte' ; 3 ; 4. let c ; 5. let value = 0.
Read more >
Changelog - Cypress Documentation
Fixed an issue with Angular Component Testing where urls within SASS/SCSS files were not being correctly resolved which could result in incomplete styling....
Read more >
svelte - Prop & store sync issue in grandchild component
i see no solution to this problem other than binding both values to be updated at the same time of the component life-cycle...
Read more >
Dynamic behavior in Svelte: working with variables and props
Our Todos.svelte component is currently just displaying static markup; let's start making it a bit more dynamic.
Read more >
Svelte Component Testing with Cypress + Vite - This Dot Labs
Cypress is a well-known e2e and integration testing framework. But since v7, a Cypress Component Test Runner was introduced, ...
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