4.0.3 • Published 1 year ago

@scaleway/jest-helpers v4.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@scaleway/jest-helpers

A package for utilities jest functions

Install

$ pnpm add @scaleway/jest-functions

How to use

Create the helpers functions

import makeHelpers from '@scaleway/jest-helpers'

const Wrapper = ({ children }) => <ThemeProvider>{children}</ThemeProvider>

export const {
  renderWithTheme,
  shouldMatchEmotionSnapshot,
  shouldMatchEmotionSnapshotWithPortal,
} = makeHelpers(Wrapper)

With a theme prop

import makeHelpers from '@scaleway/jest-helpers'
import defaultTheme from '..'

interface WrapperProps {
  theme?: typeof defaultTheme
}

const Wrapper = ({ theme, children }) => (
  <ThemeProvider theme={theme}>{children}</ThemeProvider>
)

export const {
  renderWithTheme,
  shouldMatchEmotionSnapshot,
  shouldMatchEmotionSnapshotWithPortal,
} = makeHelpers(Wrapper)

With CreateSerializerOptions

import makeHelpers from '@scaleway/jest-helpers'

const Wrapper = ({ children }) => <ThemeProvider>{children}</ThemeProvider>

export const {
  renderWithTheme,
  shouldMatchEmotionSnapshot,
  shouldMatchEmotionSnapshotWithPortal,
} = makeHelpers(Wrapper, { classNameReplacer: className => className })

renderWithTheme

Automatically uses CacheProvider from @emotion/cache. Use it with a component, optional options & optional theme.

const renderWithTheme = (
  component: ReactNode, // The component to render
  options?: RenderOptions, // RenderOptions from @testing-library/react
  theme?: Theme, // Optional theme to use which will be passed to the Wrapper above
) => ReturnType<typeof render>

shouldMatchEmotionSnapshot / shouldMatchEmotionSnapshotWithPortal

Internally it uses the renderWithTheme generated from above.

const shouldMatchEmotionSnapshot = (
  component: ReactNode, // The component to render
  options: {
    // In an object to make it backward-compatible and don't introduce any API breaking changes
    options?: RenderOptions // RenderOptions from @testing-library/react
    transform?: (node: ReturnType<typeof render>) => Promise<void> | void // (a)sync function execute between the render and the expect. You can use this if you need mockAllIsIntersecting
    theme?: Theme // Optional theme to use which will be passed to the Wrapper above
  },
) => Promise<void>
4.0.3

1 year ago

4.0.2

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

3.0.12

1 year ago

3.0.10

2 years ago

3.0.11

2 years ago

3.0.8

2 years ago

3.0.9

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.4

2 years ago

3.0.5

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.24

3 years ago

2.0.25

2 years ago

2.0.23

3 years ago

2.0.22

3 years ago

2.0.20

3 years ago

2.0.21

3 years ago

2.0.15

3 years ago

2.0.16

3 years ago

2.0.13

3 years ago

2.0.14

3 years ago

2.0.19

3 years ago

2.0.17

3 years ago

2.0.18

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.11

3 years ago

2.0.7

3 years ago

2.0.12

3 years ago

2.0.6

3 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.0

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago