Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@scaleway/jest-helpers

Package Overview
Dependencies
Maintainers
8
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scaleway/jest-helpers

A package for utilities jest functions

  • 4.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-95.24%
Maintainers
8
Weekly downloads
 
Created
Source

@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>

FAQs

Package last updated on 23 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc