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

Pass context from test/it to beforeEach #4153

Closed
4 tasks done
vim-daniel opened this issue Sep 20, 2023 · 1 comment
Closed
4 tasks done

Pass context from test/it to beforeEach #4153

vim-daniel opened this issue Sep 20, 2023 · 1 comment

Comments

@vim-daniel
Copy link

Clear and concise description of the problem

When writing tests usually you have some setup logic in the beforeEach that you want to run for each test,

For example, in this test i want each test to provide a different width, height to the url

beforeEach((context) => {
    jsdom = new JSDOM(
      html`
        <!DOCTYPE html>
        <html>
          <body>
            <div id="root"></div>
          </body>
        </html>
      `,
      {
        url: `http://localhost:3000/launch-button.html?width=${context.width }&height=${context.height}`,
      },
    );

Suggested solution

If it could be possible to do something like this:

it.extend({ width: 200, height: 200 })(
    'when height & width are big should render with large class',
    async () => {
        ...
    });

That the beforeEach context will contain the context from the it.extend

Alternative

No response

Additional context

No response

Validations

@sheremet-va
Copy link
Member

Vitest will start passing down context from it.extend in the next version #4065

@github-actions github-actions bot locked and limited conversation to collaborators Oct 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants