Skip to content

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

@claremacrae

Description

@claremacrae

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions