Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mechanism to call beforeEach() and afterEach() manually inside an it block #154

Open
claremacrae opened this issue Aug 9, 2023 · 1 comment
Labels
question Further information is requested

Comments

@claremacrae
Copy link

Thank you for creating this library. It has made it possible to test a svelte component in Jest.

There are some places where we want to make multiple calls in the same it function, instead of in 2 separate it blocks.

(This is because we wish to collate the outputs of a number of calls with different inputs in to a single test output)

For example, this works:

    it('test1', async () => {
        await doSvelteStuff();
    });
    it('test2', async () => {
        await doSvelteStuff();
    });

However, if we need this to be in the same block.

    it('test1And2', async () => {
        await doSvelteStuff();
        await doSvelteStuff();
    });

Then it gives us this kind of error:

Found multiple elements with the text: Apply

What we would like to be able to is clean up the svelte state manually in the middle of an it, something like either:

    it('test1And2', async () => {
        await doSvelteStuff();
        svelte_jester.cleanUp(); // simulate effect of afterEach()
        svelte_jester.startUp(); // simulate effect of beforeEach()
        await doSvelteStuff();
    });

Or...

    it('test1And2', async () => {
        await doSvelteStuff();
        svelte_jester.reset();
        await doSvelteStuff();
    });

Or maybe there is already a way to do this?

If it helps, we (myself and @isidore) would be happy to pair with someone on this.

@sebastianrothe
Copy link
Collaborator

This should have nothing to do with this library. Is doSvelteStuff(); an side-effect?

Maybe you can try adding await tick(); in between. This lets Svelte re-calculate all expressions.

@sebastianrothe sebastianrothe added the question Further information is requested label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants