Skip to content

Commit

Permalink
[Tests] add useRef
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan authored and ljharb committed Jun 13, 2019
1 parent b8289d0 commit b275efe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ describeWithDOM('mount', () => {
'useLayoutEffect',
'useMemo',
'useReducer',
'useRef',
'useState',
'custom',
);
Expand Down
1 change: 1 addition & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ describe('shallow', () => {
'useLayoutEffect',
'useMemo',
'useReducer',
'useRef',
'useState',
'custom',
);
Expand Down
34 changes: 34 additions & 0 deletions packages/enzyme-test-suite/test/shared/hooks/useRef.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { expect } from 'chai';

import {
describeIf,
} from '../../_helpers';

import {
useRef,
} from '../../_helpers/react-compat';

export default function describeUseRef({
hasHooks,
Wrap,
}) {
describeIf(hasHooks, 'hooks: useRef', () => {
function ComponentUsingRef() {
const id = useRef(Math.floor(100 * Math.random()));
return (
<div>{id.current}</div>
);
}

it('`current` should be the same between two renders', () => {
const wrapper = Wrap(<ComponentUsingRef />);

const childBefore = wrapper.find('div').prop('children');
wrapper.setProps({ foo: 'bar' });
const childAfter = wrapper.find('div').prop('children');

expect(childBefore).to.equal(childAfter);
});
});
}

0 comments on commit b275efe

Please sign in to comment.