Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace rerender(null) with unmount()
  • Loading branch information
jsnajdr committed Nov 2, 2022
commit e2784baea74264cbde2138267674437a0ccbf292
30 changes: 18 additions & 12 deletions packages/compose/src/hooks/use-merge-refs/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe( 'useMergeRefs', () => {
} );

it( 'should work', () => {
const { container, rerender } = render( <MergedRefs /> );
const { container, rerender, unmount } = render( <MergedRefs /> );

const originalElement = container.firstElementChild;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind altering the default tagName in MergedRefs above to be ul for example? That way instead of creating new ESLint violations for no-node-access, we'll be able to use screen.getByRole( 'list' )?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a neat trick, I used it 🙂 getByRole also ensures that the element actually exists. That was one of my worries when migrating the test: is firstElementChild really an element, or is it undefined?


Expand All @@ -95,7 +95,7 @@ describe( 'useMergeRefs', () => {
[ [], [] ],
] );

rerender( null );
unmount();

// Unmount: the initial callback functions should receive null.
expect( renderCallback.history ).toEqual( [
Expand All @@ -108,7 +108,7 @@ describe( 'useMergeRefs', () => {
} );

it( 'should work for node change', () => {
const { container, rerender } = render( <MergedRefs /> );
const { container, rerender, unmount } = render( <MergedRefs /> );

const originalElement = container.firstElementChild;

Expand All @@ -129,7 +129,7 @@ describe( 'useMergeRefs', () => {
[ [], [] ],
] );

rerender( null );
unmount();

// Unmount: the initial callback functions should receive null.
expect( renderCallback.history ).toEqual( [
Expand All @@ -142,7 +142,9 @@ describe( 'useMergeRefs', () => {
} );

it( 'should work with dependencies', () => {
const { container, rerender } = render( <MergedRefs count={ 1 } /> );
const { container, rerender, unmount } = render(
<MergedRefs count={ 1 } />
);

const originalElement = container.firstElementChild;

Expand All @@ -161,7 +163,7 @@ describe( 'useMergeRefs', () => {
[ [], [ originalElement ] ],
] );

rerender( null );
unmount();

// Unmount: current callback functions should be called with null.
expect( renderCallback.history ).toEqual( [
Expand All @@ -174,7 +176,9 @@ describe( 'useMergeRefs', () => {
} );

it( 'should simultaneously update node and dependencies', () => {
const { container, rerender } = render( <MergedRefs count={ 1 } /> );
const { container, rerender, unmount } = render(
<MergedRefs count={ 1 } />
);

const originalElement = container.firstElementChild;

Expand All @@ -199,7 +203,7 @@ describe( 'useMergeRefs', () => {
[ [], [ newElement ] ],
] );

rerender( null );
unmount();

// Unmount: current callback functions should be called with null.
expect( renderCallback.history ).toEqual( [
Expand All @@ -212,7 +216,7 @@ describe( 'useMergeRefs', () => {
} );

it( 'should work for dependency change after node change', () => {
const { container, rerender } = render( <MergedRefs /> );
const { container, rerender, unmount } = render( <MergedRefs /> );

const originalElement = container.firstElementChild;

Expand Down Expand Up @@ -248,7 +252,7 @@ describe( 'useMergeRefs', () => {
[ [], [ newElement ] ],
] );

rerender( null );
unmount();

// Unmount: current callback functions should be called with null.
expect( renderCallback.history ).toEqual( [
Expand All @@ -262,7 +266,9 @@ describe( 'useMergeRefs', () => {
} );

it( 'should allow disabling a ref', () => {
const { container, rerender } = render( <MergedRefs disable1 /> );
const { container, rerender, unmount } = render(
<MergedRefs disable1 />
);

const originalElement = container.firstElementChild;

Expand Down Expand Up @@ -295,7 +301,7 @@ describe( 'useMergeRefs', () => {
[ [], [ originalElement ] ],
] );

rerender( null );
unmount();

// Unmount: current callback functions should receive null.
expect( renderCallback.history ).toEqual( [
Expand Down