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

Jest async test using done callback syntax doesn't work with autoPreview: true #314

Open
jmasukawa opened this issue Apr 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jmasukawa
Copy link

jmasukawa commented Apr 16, 2024

Describe the bug

When jest-preview's autoPreview: true:
Using Jest's done callback syntax to write an asynchronous test (Jest documentation), the test fails because done is undefined.

With autoPreview: false, there is no issue.

Screenshots

image

Reproduce

Forked the official jest-preview stackblitz demo, then used the done async syntax in App.test.tsx, and the bug appears.

Repro: https://stackblitz.com/edit/jest-preview-zfv89j?file=src%2FApp.test.tsx

Expected behavior

With autoPreview: true, done callback should be defined, and will end the test when called.

Environment (please complete the following information)

  • OS: macOS 14.4.1
  • Browser: Chrome
  • Jest version: 27.5.1 (can also repro the bug in a private project on jest 29.7.0)

Additional context

The issue feels like it's around where the Jest it function is patched for autoPreview, here:

function patchJestFunction(it: RawIt) {
const originalIt = it;
const itWithPreview: RawIt = (name, callback, timeout) => {
let callbackWithPreview: jest.ProvidesCallback | undefined;
if (!callback) {
callbackWithPreview = undefined;
} else {
callbackWithPreview = async function (
...args: Parameters<jest.ProvidesCallback>
) {
try {
// @ts-expect-error Just forward the args
return await callback(...args);
} catch (error) {
debug();
throw error;
}
};
}
return originalIt(name, callbackWithPreview, timeout);
};
return itWithPreview;
}

@jmasukawa jmasukawa added the bug Something isn't working label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant