Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 1.45 KB

use-storybook-expect.md

File metadata and controls

39 lines (27 loc) · 1.45 KB

Use expect from '@storybook/jest' (use-storybook-expect)

Included in these configurations:

  • addon-interactions
  • flat/addon-interactions
  • recommended
  • flat/recommended

Rule Details

Storybook provides a browser compatible version of expect via the @storybook/test library (formerly available in the legacy @storybook/jest library). When writing interactions and asserting values, you should always use expect from the @storybook/test library.

Examples of incorrect code for this rule:

Default.play = async () => {
  // using global expect from Jest. Will break on the browser
  await expect(123).toEqual(123)
}

Examples of correct code for this rule:

// correct import.
import { expect } from '@storybook/test'
// or this, which is now considered legacy
import { expect } from '@storybook/jest'

Default.play = async () => {
  // using imported expect from storybook package
  await expect(123).toEqual(123)
}

When Not To Use It

This rule should not be applied in test files. Please ensure you are defining the storybook rules only for story files. You can see more details here.