Skip to content
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

Move off Enzyme, to React Testing Library #2935

Merged
merged 24 commits into from
Apr 18, 2023
Merged

Conversation

JamesBurnside
Copy link
Member

@JamesBurnside JamesBurnside commented Apr 14, 2023

What

Migrate from Enzyme to react testing library

Why

See: Enzyme is dead. Enzyme has no, and is unlikely to have, any react 18 support. So we are migrating to a new testing package.

related: #2939, #1900

How Tested

Unit tests in CI should all pass

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

github-actions bot commented Apr 14, 2023

CallWithChat bundle size is increased❗.

  • Current size: 10051819
  • Base size: 10051723
  • Diff size: 96

@github-actions
Copy link
Contributor

github-actions bot commented Apr 14, 2023

Chat bundle size is increased❗.

  • Current size: 9701353
  • Base size: 9701325
  • Diff size: 28

@github-actions
Copy link
Contributor

github-actions bot commented Apr 14, 2023

Calling bundle size is increased❗.

  • Current size: 9658506
  • Base size: 9658410
  • Diff size: 96

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

expect(callComposite.props().rtl).toBe(mockBaseCompositeProps.rtl);
expect(callComposite.props().onFetchAvatarPersonaData).toBe(mockBaseCompositeProps.onFetchAvatarPersonaData);
expect(callComposite.props().onFetchParticipantMenuItems).toBe(mockBaseCompositeProps.onFetchParticipantMenuItems);
expect(container.querySelector('[data-ui-id="lobby-page"]')).toBeTruthy();
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the only test I changed what was tested. Before the test simply checked that the props we passed in were the props the composite received -- this doesn't make sense for a test, so I updated this to validate the composite successfully rendered a lobby page as the mock adapter depicts

Copy link
Member

@dmceachernmsft dmceachernmsft left a comment

Choose a reason for hiding this comment

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

looks great just some general fact finding questions! 😊

});

test('Should override button label with `strings` prop', async () => {
const testLocale = createTestLocale({ devicesButton: { label: Math.random().toString() } });
const devicesButtonStrings = { label: Math.random().toString() };
const component = mountWithLocalization(
renderWithLocalization(
Copy link
Member

Choose a reason for hiding this comment

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

so with this change does this mean these tests do actually create a DOM?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sort of - The testing library's terminology uses the word render, but it doesn't render anything actual graphical, just renders an in memory DOM. Because we use jest, this library lets the testing library dictate who implements that DOM so for us its https://github.com/jsdom/jsdom

testLocale.strings.dialpad.placeholderText
);
renderWithLocalization(<Dialpad />, testLocale);
expect(screen.getByRole('textbox').getAttribute('placeholder')).toBe(testLocale.strings.dialpad.placeholderText);
Copy link
Member

Choose a reason for hiding this comment

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

is screen a property that just exists inside the test runner we can query?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, its basically a way of saying - hey query what's on the "screen" (screen isn't a real screen, just an in memory interpretation of a screen). Ideally we'd only use screen for queries but it can't query anything arbitrary (like data-ui-id) so for those I've used the container returned by the render method

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

wrapper.simulate('touchend');
fireEvent.touchStart(videoTile);
jest.runAllTimers();
fireEvent.touchEnd(videoTile);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this conversion. I was worried about triggering touch events with React Testing Library. Nicely done.

@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable @typescript-eslint/no-non-null-assertion */
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious why this was necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

Typescript isn't smart enough to know that:

var a: someType | undefined;

expect(a).toBeTruthy();
expect(a.something).toBe(...); // Typescript complains here that a might be undefined, but it actually can't be undefined because of the previous `expect`

// so I instead do:
expect(a).toBeTruthy();
expect(a!.something).toBe(...); // notice the ! after the a, this is the non-null assertion, which by default we disallow as its should be used more sparingly

container: HTMLElement;
} => {
const { rerender, container } = render(
withLiveAnnouncerContext(<LocalizationProvider locale={locale}>{node}</LocalizationProvider>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to wrap with LiveAnnouncer?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just gets rid of warnings from the react-aria-live package. This warning already exists in our current tests, but this removes the warning

Copy link
Member Author

Choose a reason for hiding this comment

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

(we're moving off this package shortly as it does not support react18 so this was a super quick fix to the warning)

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

Failed to pass the Static HTML UI Test. If this PR is for UI change and the error is snapshot mismatch, please add "update_snapshots" label to the PR for updating the snapshot.

@github-actions
Copy link
Contributor

Failed to pass the UI Test. If this PR is for UI change and the error is snapshot mismatch, please add "update_snapshots" label to the PR for updating the snapshot.

@github-actions
Copy link
Contributor

Failed to pass the Static HTML UI Test. If this PR is for UI change and the error is snapshot mismatch, please add "update_snapshots" label to the PR for updating the snapshot.

@JamesBurnside JamesBurnside merged commit 318e0a9 into main Apr 18, 2023
29 checks passed
@JamesBurnside JamesBurnside deleted the jaburnsi/move-off-enzyme branch April 18, 2023 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants