From bdc92576ac34014cd317a4d7b6f7f9c61e0ac669 Mon Sep 17 00:00:00 2001 From: Pascal Date: Thu, 1 Jun 2023 15:39:04 +0200 Subject: [PATCH 1/2] added information that jest is not globally available this was very hard to find out so maybe someones would be happy to have that information here. --- docs/essentials/interactions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/essentials/interactions.md b/docs/essentials/interactions.md index a8c212b15c12..245c02cb3384 100644 --- a/docs/essentials/interactions.md +++ b/docs/essentials/interactions.md @@ -82,3 +82,5 @@ The above example uses the `canvasElement` to scope your element queries to the While you can refer to the [Testing Library documentation](https://testing-library.com/docs/) for details on how to use it, there's an important detail that's different when using the Storybook wrapper: **method invocations must be `await`-ed**. It allows you to step back and forth through your interactions using the debugger. Any `args` that have been marked as an Action, either using the [argTypes annotation](./actions.md#action-argtype-annotation) or the [argTypesRegex](./actions.md#automatically-matching-args), will be automatically converted to a [Jest mock function](https://jestjs.io/docs/mock-function-api) (spy). This allows you to make assertions about calls to these functions. + +> Note: If you need to use jest native spys like `jest.fn()` the import of jest over `import {jest} from "@storybook/jest"` is needed, as jest is not available globally. From d0293bb1588731ff89eece902ba8be73be611214 Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 26 Jun 2023 09:19:26 +0200 Subject: [PATCH 2/2] applied suggested changes --- docs/essentials/interactions.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/essentials/interactions.md b/docs/essentials/interactions.md index 245c02cb3384..6baff2197774 100644 --- a/docs/essentials/interactions.md +++ b/docs/essentials/interactions.md @@ -83,4 +83,8 @@ While you can refer to the [Testing Library documentation](https://testing-libra Any `args` that have been marked as an Action, either using the [argTypes annotation](./actions.md#action-argtype-annotation) or the [argTypesRegex](./actions.md#automatically-matching-args), will be automatically converted to a [Jest mock function](https://jestjs.io/docs/mock-function-api) (spy). This allows you to make assertions about calls to these functions. -> Note: If you need to use jest native spys like `jest.fn()` the import of jest over `import {jest} from "@storybook/jest"` is needed, as jest is not available globally. +
+ +ℹ️ To mock functions in your Storybook stories for reliable and isolated component testing, use the `jest` import from `@storybook/jest`. This allows you to avoid configuring Jest globally in your project. + +