Skip to content

Commit

Permalink
Merge pull request #107 from trovit/remove-jest-profiler
Browse files Browse the repository at this point in the history
Remove dependency with react-jest-profiler
  • Loading branch information
mariosanchez authored May 2, 2024
2 parents e14cc6b + 0439604 commit 479b308
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
18 changes: 3 additions & 15 deletions packages/reffects-store/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/reffects-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-prettier": "^3.0.1",
"jest": "^26.6.3",
"jest-react-profiler": "^0.1.3",
"jest-when": "^3.4.1",
"prettier": "^1.16.4",
"reffects": "^1.6.1-alpha.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/reffects-store/src/subscription/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withProfiler } from 'jest-react-profiler';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { render } from '@testing-library/react';
import withProfiler from './rendererProfiler';
import subscribe from '.';
import * as storeModule from '../store';
import '@testing-library/jest-dom';
Expand Down
23 changes: 23 additions & 0 deletions packages/reffects-store/src/subscription/rendererProfiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createElement, Profiler } from 'react';

export default function withProfiler(Component) {
const onRender = () => {
SnapshotProfiler.__numCommits++;
};
const SnapshotProfiler = props =>
createElement(
Profiler,
{ id: 'withProfiler', onRender },
createElement(Component, props)
);
SnapshotProfiler.__numCommits = 0;
return SnapshotProfiler;
}

function toHaveCommittedTimes(SnapshotProfiler, expectedNumCommits) {
expect(SnapshotProfiler.__numCommits).toBe(expectedNumCommits);
SnapshotProfiler.__numCommits = 0;
return { pass: true };
}

expect.extend({ toHaveCommittedTimes });
12 changes: 6 additions & 6 deletions packages/reffects-store/src/subscription/useSelector.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withProfiler } from 'jest-react-profiler';
import React from 'react';
import { render } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import withProfiler from './rendererProfiler';
import * as storeModule from '../store';
import useSelector from './useSelector';
import '@testing-library/jest-dom';
Expand Down Expand Up @@ -73,12 +73,12 @@ describe('useSelector hook', () => {
});

it.each([
['primitive', 1, '1'],
['array', [1, 2], '[1,2]'],
['object', { b: 2 }, '{"b":2}'],
['primitive', 1, 1, '1'],
['array', [1, 2], [1, 2], '[1,2]'],
['object', { b: 2 }, { b: 2 }, '{"b":2}'],
])(
"shouldn't update the component using it when the state is the same using %s",
(_, value, expected) => {
(_, value, newValue, expected) => {
const initialProps = { a: value };
const store = storeModule;
store.initialize(initialProps);
Expand All @@ -91,7 +91,7 @@ describe('useSelector hook', () => {
expect(getByText(expected)).toBeInTheDocument();

act(() => {
store.setState({ path: ['a'], newValue: value });
store.setState({ path: ['a'], newValue });
store.setState({ path: ['koko'], newValue: 'loko' });
});

Expand Down

0 comments on commit 479b308

Please sign in to comment.