-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Jest Preset: Major version upgrade for Jest in all packages #20766
Conversation
I still see some failing tests that need to be further investigated. It looks like all of them are related to DOM structure or interactions I would appreciate help from @diegohaz, @getdave or @nerrad. Would it help to land one of the PRs with Summary of all failing tests
FAIL packages/components/src/sandbox/test/index.js
● should rerender with new emdeded content if html prop changes
expect(jest.fn()).not.toHaveErrored(expected)
Expected mock function not to be called but it was called with:
["Error: Uncaught [TypeError: Cannot read property 'body' of undefined]
at reportException (/Users/gziolo/Projects/gutenberg/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:62:24)
at notifyMutationObservers (/Users/gziolo/Projects/gutenberg/node_modules/jsdom/lib/jsdom/living/helpers/mutation-observers.js:166:
11)
at /Users/gziolo/Projects/gutenberg/node_modules/jsdom/lib/jsdom/living/helpers/mutation-observers.js:133:5
at processTicksAndRejections (internal/process/task_queues.js:97:5)", [TypeError: Cannot read property 'body' of undefined]]
34 | function assertExpectedCalls() {
35 | if ( spy.assertionsNumber === 0 && spy.mock.calls.length > 0 ) {
> 36 | expect( console ).not[ matcherName ]();
| ^
37 | }
38 | }
39 |
at Object.assertExpectedCalls (packages/jest-console/src/index.js:36:4)
FAIL packages/components/src/navigable-container/test/tabbable.js
● TabbableContainer › should navigate by keypresses
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
88 | ) {
89 | const interaction = fireKeyDown( container, keyCode, shiftKey );
> 90 | expect( currentIndex ).toBe( expectedActiveIndex );
| ^
91 | expect( interaction.stopped ).toBe( expectedStop );
92 | }
93 |
at assertKeyDown (packages/components/src/navigable-container/test/tabbable.js:90:27)
at Object.<anonymous> (packages/components/src/navigable-container/test/tabbable.js:94:3)
● TabbableContainer › should navigate by keypresses and stop at edges
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
145 | ) {
146 | const interaction = fireKeyDown( container, keyCode, shiftKey );
> 147 | expect( currentIndex ).toBe( expectedActiveIndex );
| ^
148 | expect( interaction.stopped ).toBe( expectedStop );
149 | }
150 |
at assertKeyDown (packages/components/src/navigable-container/test/tabbable.js:147:27)
at Object.<anonymous> (packages/components/src/navigable-container/test/tabbable.js:151:3)
FAIL packages/components/src/navigable-container/test/menu.js
● NavigableMenu › vertical: should navigate by up and down
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
83 | function assertKeyDown( keyCode, expectedActiveIndex, expectedStop ) {
84 | const interaction = fireKeyDown( container, keyCode, false );
> 85 | expect( currentIndex ).toBe( expectedActiveIndex );
| ^
86 | expect( interaction.stopped ).toBe( expectedStop );
87 | }
88 |
at assertKeyDown (packages/components/src/navigable-container/test/menu.js:85:27)
at Object.<anonymous> (packages/components/src/navigable-container/test/menu.js:89:3)
● NavigableMenu › vertical: should navigate by up and down, and stop at edges
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
137 | function assertKeyDown( keyCode, expectedActiveIndex, expectedStop ) {
138 | const interaction = fireKeyDown( container, keyCode, false );
> 139 | expect( currentIndex ).toBe( expectedActiveIndex );
| ^
140 | expect( interaction.stopped ).toBe( expectedStop );
141 | }
142 |
at assertKeyDown (packages/components/src/navigable-container/test/menu.js:139:27)
at Object.<anonymous> (packages/components/src/navigable-container/test/menu.js:143:3)
● NavigableMenu › horizontal: should navigate by left and right
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
193 | function assertKeyDown( keyCode, expectedActiveIndex, expectedStop ) {
194 | const interaction = fireKeyDown( container, keyCode, false );
> 195 | expect( currentIndex ).toBe( expectedActiveIndex );
| ^
196 | expect( interaction.stopped ).toBe( expectedStop );
197 | }
198 |
at assertKeyDown (packages/components/src/navigable-container/test/menu.js:195:27)
at Object.<anonymous> (packages/components/src/navigable-container/test/menu.js:199:3)
● NavigableMenu › horizontal: should navigate by left and right, and stop at edges
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
247 | function assertKeyDown( keyCode, expectedActiveIndex, expectedStop ) {
248 | const interaction = fireKeyDown( container, keyCode, false );
> 249 | expect( currentIndex ).toBe( expectedActiveIndex );
| ^
250 | expect( interaction.stopped ).toBe( expectedStop );
251 | }
252 |
at assertKeyDown (packages/components/src/navigable-container/test/menu.js:249:27)
at Object.<anonymous> (packages/components/src/navigable-container/test/menu.js:253:3)
● NavigableMenu › both: should navigate by up/down and left/right
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
292 | function assertKeyDown( keyCode, expectedActiveIndex, expectedStop ) {
293 | const interaction = fireKeyDown( container, keyCode );
> 294 | expect( currentIndex ).toBe( expectedActiveIndex );
| ^
295 | expect( interaction.stopped ).toBe( expectedStop );
296 | }
297 |
at assertKeyDown (packages/components/src/navigable-container/test/menu.js:294:27)
at Object.<anonymous> (packages/components/src/navigable-container/test/menu.js:298:3)
FAIL packages/components/src/higher-order/with-focus-return/test/index.js
● withFocusReturn() › testing rendering and focus handling › should not switch focus back to the bound focus element
expect(received).toBe(expected) // Object.is equality
Expected: <button />
Received: null
77 | const mountedComposite = renderer.create( <Composite /> );
78 |
> 79 | expect( getInstance( mountedComposite ).activeElementOnMount ).toBe(
| ^
80 | activeElement
81 | );
82 |
at Object.<anonymous> (packages/components/src/higher-order/with-focus-return/test/index.js:79:67)
● withFocusReturn() › testing rendering and focus handling › should switch focus back when unmounted while having focus
expect(received).toBe(expected) // Object.is equality
Expected: <button />
Received: null
99 | // Should return to the activeElement saved with this component.
100 | wrapper.unmount();
> 101 | expect( document.activeElement ).toBe( activeElement );
| ^
102 | } );
103 |
104 | it( 'should switch focus to the most recent still-available focus target', () => {
at Object.<anonymous> (packages/components/src/higher-order/with-focus-return/test/index.js:101:37)
● withFocusReturn() › testing rendering and focus handling › should switch focus to the most recent still-available focus target
expect(jest.fn()).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
140 | expect(
141 | wrapper.find( 'input[name="first"]' ).getDOMNode().focus
> 142 | ).toHaveBeenCalled();
| ^
143 | } );
144 | } );
145 | } );
at Object.<anonymous> (packages/components/src/higher-order/with-focus-return/test/index.js:142:6)
FAIL packages/components/src/popover/test/index.js
● Popover › should focus when opening in response to keyboard event
expect(received).toBe(expected) // Object.is equality
Expected: <div class="components-popover__content" tabindex="-1" />
Received: null
48 | 'components-popover__content'
49 | );
> 50 | expect( document.activeElement ).toBe( content );
| ^
51 | } );
52 | } );
53 |
at packages/components/src/popover/test/index.js:50:37
at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:21643:12)
at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1002:14)
at Object.act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1418:12)
at Object.<anonymous> (packages/components/src/popover/test/index.js:41:13)
FAIL packages/components/src/toolbar/test/index.js
● Toolbar › ToolbarGroup › should render an empty node, when controls are not passed
expect(received).toBeNull()
Received: ""
29 | it( 'should render an empty node, when controls are not passed', () => {
30 | const wrapper = mount( <Toolbar /> );
> 31 | expect( wrapper.html() ).toBeNull();
| ^
32 | } );
33 |
34 | it( 'should render an empty node, when controls are empty', () => {
at Object.<anonymous> (packages/components/src/toolbar/test/index.js:31:29)
● Toolbar › ToolbarGroup › should render an empty node, when controls are empty
expect(received).toBeNull()
Received: ""
34 | it( 'should render an empty node, when controls are empty', () => {
35 | const wrapper = mount( <Toolbar controls={ [] } /> );
> 36 | expect( wrapper.html() ).toBeNull();
| ^
37 | } );
38 |
39 | it( 'should render a list of controls with buttons', () => {
at Object.<anonymous> (packages/components/src/toolbar/test/index.js:36:29)
Test Suites: 6 failed, 349 passed, 355 total
Tests: 14 failed, 3752 passed, 3766 total
Snapshots: 287 passed, 287 total
Time: 23.799s, estimated 100s |
Size Change: 0 B Total Size: 890 kB ℹ️ View Unchanged
|
I would try to install |
You read my mind. I had the same thought this weekend after reading that Enzyme is going to be maintained by the community. I’d be in favor of landing your PR that introduces RTL and then we can refactor those tests as follow-up. It should unblock this PR. |
329f170
to
de8f51a
Compare
fe59e79
to
2b683cf
Compare
There is only one failure left: FAIL packages/components/src/sandbox/test/index.js
● should rerender with new emdeded content if html prop changes
expect(jest.fn()).not.toHaveErrored(expected)
Expected mock function not to be called but it was called with:
["Error: Uncaught [TypeError: Cannot read property 'body' of undefined]
at reportException (/Users/gziolo/Projects/gutenberg/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:62:24)
at notifyMutationObservers (/Users/gziolo/Projects/gutenberg/node_modules/jsdom/lib/jsdom/living/helpers/mutation-observers.js:166:11)
at /Users/gziolo/Projects/gutenberg/node_modules/jsdom/lib/jsdom/living/helpers/mutation-observers.js:133:5
at processTicksAndRejections (internal/process/task_queues.js:97:5)", [TypeError: Cannot read property 'body' of undefined]]
34 | function assertExpectedCalls() {
35 | if ( spy.assertionsNumber === 0 && spy.mock.calls.length > 0 ) {
> 36 | expect( console ).not[ matcherName ]();
| ^
37 | }
38 | }
39 |
at Object.assertExpectedCalls (packages/jest-console/src/index.js:36:4)
Test Suites: 1 failed, 374 passed, 375 total
Tests: 1 failed, 4141 passed, 4142 total
Snapshots: 286 passed, 286 total
Time: 34.226s |
2b683cf
to
3a9ec79
Compare
3a9ec79
to
c37eda9
Compare
I sorted out all the failing tests. This PR is ready to go on the technical level. Now the question is whether we like the tests refactored to use React Testing Library? I'm happy to extract refactorings to their own PR if that help to move forward 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a fair point that the test refactoring could have been reserved for a separate pull request. The changes are pretty straight-forward to follow, though. I'm fine to merge as-is 👍
f05ad58
to
2dc7830
Compare
* refactor storybook * convert to typescript * fix ComponentProps * add changelog. * fix imports order * use WordPressComponentProps. * add example * Update packages/components/src/disabled/types.ts Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com> * Update packages/components/src/disabled/index.tsx Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com> * Update packages/components/src/disabled/index.tsx Co-authored-by: Petter Walbø Johnsgård <petter@dekode.no> * Update packages/components/src/disabled/index.tsx Co-authored-by: Petter Walbø Johnsgård <petter@dekode.no> * Remove unused imports. * Rewrite to Testing-library `will disable all fields` * Rewrite to Testing-library `should cleanly un-disable via reconciliation` * use rerender * refactor test. * replace react-dom/test-utils to testing-library. * remove unnecessary MutationObserver stab. @see #20766 #20514 * Convert to typescript. * add story for contentEditable * add control settings. * fix changelog * Update packages/components/CHANGELOG.md Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com> * Omit ref. * avoid querying * rename div. * test before rerender * Simplify * Update packages/components/src/disabled/test/index.tsx Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com> * test for sneaky DOM manipulation * Fix `isDisabled` so that it keeps its value even if it is changed. * add default args * Revert "Fix `isDisabled` so that it keeps its value even if it is changed." This reverts commit 28820f0. * Update packages/components/src/disabled/test/index.tsx * Update packages/components/CHANGELOG.md Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com> Co-authored-by: Petter Walbø Johnsgård <petter@dekode.no>
Description
This PR updated Jest to the last version. It also upgrades all related dependencies like
enzyme
orjsdom
.It was triggered by the issue discovered by @brentswisher in #20514. Related comments:
TODO
How has this been tested?
Executed:
npm run test-unit
npm run test-e2e
There are still some unit tests failing ...
There is no observed impact on e2e tests.
Types of changes
Checklist: