jest-react-profiler

Jest helpers for working with the React Profiler API.

  • Owner: bvaughn/jest-react-profiler
  • Platform:
  • License::
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

jest-react-profiler

Jest helpers for working with the React Profiler API.

Installation

yarn add jest-react-profiler -D

Example usage

// Requiring this package will automatically register its custom matchers.
const { withProfiler } = require("jest-react-profiler");

function Greeting({ name }) {
  return <div>Hello, {name}</div>;
}

// Decorate a React component with a test Profiler:
const GreetingWithProfiler = withProfiler(Greeting);

// Next render it like normal:
render(
  <GreetingWithProfiler name="Brian" />,
  document.createElement("div")
);

// Now you can specify an expected number of commits:
expect(GreetingWithProfiler).toHaveCommittedTimes(1);

// Or use a Jest snapshot to track the value:
expect(GreetingWithProfiler).toMatchNumCommits();

API

toHaveCommittedTimes(number)

Verifies that the test profiler component committed a specific number of times since the last time the matcher was called.

This matcher resets the commit count between calls to simplify large test cases.

toMatchNumCommits()

Uses Jest snapshots to verify that a test profiler component committed the same number of times as when it was last run.

This matcher verifies that at least once commit has occurred in order to avoid false positives when used with a renderer that does not have profiling enabled.

This matcher resets the commit count between calls to simplify large test cases.

Main metrics

Overview
Name With Ownerbvaughn/jest-react-profiler
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:
所有者活动
Created At2018-12-17 18:34:39
Pushed At2018-12-20 17:50:31
Last Commit At2018-12-20 09:50:25
Release Count0
用户参与
Stargazers Count277
Watchers Count3
Fork Count4
Commits Count11
Has Issues Enabled
Issues Count3
Issue Open Count1
Pull Requests Count2
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private