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

beforeEach return fn doesn't receive context that afterEach receives #4030

Closed
6 tasks done
luixo opened this issue Aug 28, 2023 · 1 comment · Fixed by #4065
Closed
6 tasks done

beforeEach return fn doesn't receive context that afterEach receives #4030

luixo opened this issue Aug 28, 2023 · 1 comment · Fixed by #4065

Comments

@luixo
Copy link

luixo commented Aug 28, 2023

Describe the bug

Consider code:
test1.spec.ts

import { test as originalTest } from 'vitest';

type Fixture = { foo: number };

const test = originalTest.extend<Fixture>({
  foo: async ({}, use) => {
    await use(1);
  },
});
beforeEach<Fixture>(({ foo })=> {
  console.log(`beforeEach ${foo}`);
});
afterEach<Fixture>(({ foo }) => {
  console.log(`afterEach ${foo}`);
});

In this case we'll get not data in beforeEach as expected, but afterEach can access the data.

beforeEach undefined
afterEach 1

Consider pretty similar case
test2.spec.ts

import { test as originalTest } from 'vitest';

type Fixture = { foo: number };

const test = originalTest.extend<Fixture>({
  foo: async ({}, use) => {
    await use(1);
  },
});
beforeEach<Fixture>(({ foo })=> {
  console.log(`beforeEach ${foo}`);
  return ({ foo: afterFoo }) => {
    console.log(`afterEach ${foo} / ${afterFoo}`);
  };
});

This code will throw on beforeEach callback (effectively an analogue to afterEach), I would expect to actually see:

beforeEach undefined
afterEach undefined / 1

Reproduction

See above

System Info

Not applicable

Used Package Manager

yarn

Validations

@sheremet-va
Copy link
Member

This looks like a bug, but I would expect it to work like test.beforeEach because you can define separate contexts at the top level

@github-actions github-actions bot locked and limited conversation to collaborators Sep 29, 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

Successfully merging a pull request may close this issue.

2 participants