Skip to content

test: Add React 18 to test matrix #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
# Otherwise how would we know if a specific React version caused the failure?
fail-fast: false
matrix:
REACT_DIST: [16, 17]

REACT_DIST: [16, 17, next]
# Unstable release channel so let's not block a potential release of `react-transition-group`
continue-on-error: ${{ matrix.REACT_DIST == 'next' }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@semantic-release/npm": "^7.0.5",
"@storybook/addon-actions": "^6.3.4",
"@storybook/react": "^6.3.4",
"@testing-library/react": "^12.1.2",
"@testing-library/react": "alpha",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"astroturf": "^0.10.4",
"babel-eslint": "^10.1.0",
Expand Down
148 changes: 88 additions & 60 deletions test/CSSTransition-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from './utils';
import { render, waitFor } from './utils';

import CSSTransition from '../src/CSSTransition';
import TransitionGroup from '../src/TransitionGroup';
Expand Down Expand Up @@ -36,8 +36,9 @@ describe('CSSTransition', () => {
});

describe('entering', () => {
it('should apply classes at each transition state', (done) => {
it('should apply classes at each transition state', async () => {
let count = 0;
let done = false;
const nodeRef = React.createRef();
const { setProps } = render(
<CSSTransition nodeRef={nodeRef} timeout={10} classNames="test">
Expand All @@ -63,12 +64,16 @@ describe('CSSTransition', () => {
onEntered() {
expect(nodeRef.current.className).toEqual('test-enter-done');
expect(count).toEqual(2);
done();
done = true;
},
});

await waitFor(() => {
expect(done).toBe(true);
});
});

it('should apply custom classNames names', (done) => {
it('should apply custom classNames names', async () => {
let count = 0;
const nodeRef = React.createRef();
const { setProps } = render(
Expand Down Expand Up @@ -102,15 +107,17 @@ describe('CSSTransition', () => {

onEntered() {
expect(nodeRef.current.className).toEqual('custom-super-done');
expect(count).toEqual(2);
done();
},
});

await waitFor(() => {
expect(count).toEqual(2);
});
});
});

describe('appearing', () => {
it('should apply appear classes at each transition state', (done) => {
it('should apply appear classes at each transition state', async () => {
let count = 0;
const nodeRef = React.createRef();
render(
Expand All @@ -137,17 +144,21 @@ describe('CSSTransition', () => {
expect(nodeRef.current.className).toEqual(
'appear-test-appear-done appear-test-enter-done'
);
expect(count).toEqual(2);
done();
}}
>
<div ref={nodeRef} />
</CSSTransition>
);

await waitFor(() => {
expect(count).toEqual(2);
});
});

it('should lose the "*-appear-done" class after leaving and entering again', (done) => {
it('should lose the "*-appear-done" class after leaving and entering again', async () => {
const nodeRef = React.createRef();
let entered = false;
let exited = false;
const { setProps } = render(
<CSSTransition
timeout={10}
Expand All @@ -156,31 +167,45 @@ describe('CSSTransition', () => {
in={true}
appear={true}
onEntered={() => {
setProps({
in: false,
onEntered: () => {},
onExited: () => {
expect(nodeRef.current.className).toBe('appear-test-exit-done');
setProps({
in: true,
onEntered: () => {
expect(nodeRef.current.className).toBe(
'appear-test-enter-done'
);
done();
},
});
},
});
entered = true;
}}
>
<div ref={nodeRef} />
</CSSTransition>
);

await waitFor(() => {
expect(entered).toEqual(true);
});
setProps({
in: false,
onEntered: () => {},
onExited: () => {
exited = true;
},
});

await waitFor(() => {
expect(exited).toEqual(true);
});
expect(nodeRef.current.className).toBe('appear-test-exit-done');
entered = false;
setProps({
in: true,
onEntered: () => {
entered = true;
},
});

await waitFor(() => {
expect(entered).toEqual(true);
});
expect(nodeRef.current.className).toBe('appear-test-enter-done');
});

it('should not add undefined when appearDone is not defined', (done) => {
it('should not add undefined when appearDone is not defined', async () => {
const nodeRef = React.createRef();
let done = false;
render(
<CSSTransition
timeout={10}
Expand All @@ -195,15 +220,19 @@ describe('CSSTransition', () => {
onEntered={(isAppearing) => {
expect(isAppearing).toEqual(true);
expect(nodeRef.current.className).toEqual('');
done();
done = true;
}}
>
<div ref={nodeRef} />
</CSSTransition>
);

await waitFor(() => {
expect(done).toEqual(true);
});
});

it('should not be appearing in normal enter mode', (done) => {
it('should not be appearing in normal enter mode', async () => {
let count = 0;
const nodeRef = React.createRef();
render(
Expand Down Expand Up @@ -237,10 +266,12 @@ describe('CSSTransition', () => {
expect(nodeRef.current.className).toEqual(
'not-appear-test-enter-done'
);
expect(count).toEqual(2);
done();
},
});

await waitFor(() => {
expect(count).toEqual(2);
});
});

it('should not enter the transition states when appear=false', () => {
Expand Down Expand Up @@ -269,7 +300,7 @@ describe('CSSTransition', () => {
});

describe('exiting', () => {
it('should apply classes at each transition state', (done) => {
it('should apply classes at each transition state', async () => {
let count = 0;
const nodeRef = React.createRef();
const { setProps } = render(
Expand All @@ -295,13 +326,15 @@ describe('CSSTransition', () => {

onExited() {
expect(nodeRef.current.className).toEqual('test-exit-done');
expect(count).toEqual(2);
done();
},
});

await waitFor(() => {
expect(count).toEqual(2);
});
});

it('should apply custom classNames names', (done) => {
it('should apply custom classNames names', async () => {
let count = 0;
const nodeRef = React.createRef();
const { setProps } = render(
Expand Down Expand Up @@ -336,13 +369,15 @@ describe('CSSTransition', () => {

onExited() {
expect(nodeRef.current.className).toEqual('custom-super-done');
expect(count).toEqual(2);
done();
},
});

await waitFor(() => {
expect(count).toEqual(2);
});
});

it('should support empty prefix', (done) => {
it('should support empty prefix', async () => {
let count = 0;

const nodeRef = React.createRef();
Expand All @@ -367,10 +402,12 @@ describe('CSSTransition', () => {

onExited() {
expect(nodeRef.current.className).toEqual('exit-done');
expect(count).toEqual(2);
done();
},
});

await waitFor(() => {
expect(count).toEqual(2);
});
});
});

Expand Down Expand Up @@ -412,20 +449,7 @@ describe('CSSTransition', () => {
<Test direction="down" text="foo" nodeRef={nodeRef.foo} />
);

const rerender = (getProps) =>
new Promise((resolve) =>
setProps({
onEnter: undefined,
onEntering: undefined,
onEntered: undefined,
onExit: undefined,
onExiting: undefined,
onExited: undefined,
...getProps(resolve),
})
);

await rerender((resolve) => ({
setProps({
direction: 'up',
text: 'bar',
nodeRef: nodeRef.bar,
Expand All @@ -439,11 +463,14 @@ describe('CSSTransition', () => {
expect(nodeRef.bar.current.className).toEqual(
'up-enter up-enter-active'
);
resolve();
},
}));
});

await waitFor(() => {
expect(count).toEqual(2);
});

await rerender((resolve) => ({
setProps({
direction: 'down',
text: 'foo',
nodeRef: nodeRef.foo,
Expand All @@ -457,11 +484,12 @@ describe('CSSTransition', () => {
onEntered() {
count++;
expect(nodeRef.foo.current.className).toEqual('down-enter-done');
resolve();
},
}));
});

expect(count).toEqual(4);
await waitFor(() => {
expect(count).toEqual(4);
});
});
});
});
4 changes: 3 additions & 1 deletion test/CSSTransitionGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ describe('CSSTransitionGroup', () => {
ReactDOM.unmountComponentAtNode(container);

// Testing that no exception is thrown here, as the timeout has been cleared.
jest.runAllTimers();
act(() => {
jest.runAllTimers();
});
});

it('should handle unmounted elements properly', () => {
Expand Down
6 changes: 6 additions & 0 deletions test/SwitchTransition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ describe('SwitchTransition', () => {
act(() => {
jest.runAllTimers();
});
act(() => {
jest.runAllTimers();
});
Comment on lines +109 to +111
Copy link
Member

Choose a reason for hiding this comment

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

Why is this call added?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me check. I think it was due to previous tests relying on implementation details related to React scheduling timings. Will check what specifically was happening.

expect(log).toEqual([
'exit',
'exiting',
Expand Down Expand Up @@ -137,6 +140,9 @@ describe('SwitchTransition', () => {
act(() => {
jest.runAllTimers();
});
act(() => {
jest.runAllTimers();
});
expect(log).toEqual([
'enter',
'entering',
Expand Down
Loading