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

[tests] Remove enzyme from QualityMetrics tests #1684

Merged
merged 10 commits into from
Aug 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,35 @@
// limitations under the License.

import React from 'react';
import { shallow } from 'enzyme';

import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/';
import BannerText from './BannerText';

describe('BannerText', () => {
it('renders null when props.bannerText is falsy', () => {
expect(shallow(<BannerText />).type()).toBe(null);
const { container } = render(<BannerText />);
expect(container.firstChild).toBe(null);
});

it('renders header when props.bannerText is a string', () => {
expect(shallow(<BannerText bannerText="foo text" />)).toMatchSnapshot();
Copy link
Member

Choose a reason for hiding this comment

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

Since toMatchSnapshot() is no longer used, the snapshots created for this test needs to be purged.
You can use the command yarn test --updateSnapshot for that.

render(<BannerText bannerText="foo text" />);
expect(screen.getByText('foo text')).toBeInTheDocument();
});

it('renders styled header when props.bannerText is a styled value', () => {
expect(
shallow(
<BannerText
bannerText={{
styling: {
background: 'red',
color: 'white',
},
value: 'foo text',
}}
/>
)
).toMatchSnapshot();
Copy link
Member

Choose a reason for hiding this comment

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

Snapshots need to be purged for this too. Otherwise, the tests would pass, but CI will fail.

render(
<BannerText
bannerText={{
styling: {
background: 'red',
color: 'white',
},
value: 'foo text',
}}
/>
);

expect(screen.getByText('foo text')).toBeInTheDocument();
expect(screen.getByText('foo text')).toHaveStyle('background: red; color: white;');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@
// limitations under the License.

import React from 'react';
import { shallow } from 'enzyme';

import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import CountCard from './CountCard';

describe('CountCard', () => {
const count = 108;
const title = 'Test Title';
const examples = ['Examples'];

it('renders null when props.count or props.title is absent', () => {
expect(shallow(<CountCard count={count} />).type()).toBe(null);
expect(shallow(<CountCard title={title} />).type()).toBe(null);
const { container: containerWithoutTitle } = render(<CountCard count={count} />);
expect(containerWithoutTitle.firstChild).toBe(null);
const { container: containerWithoutCount } = render(<CountCard title={title} />);
expect(containerWithoutCount.firstChild).toBe(null);
});

it('renders as expected when given count and title', () => {
expect(shallow(<CountCard count={count} title={title} />)).toMatchSnapshot();
render(<CountCard count={count} title={title} />);

expect(screen.getByText(count)).toBeInTheDocument();
expect(screen.getByText(title)).toBeInTheDocument();
});

it('renders as expected when given count, title, and examples', () => {
expect(shallow(<CountCard count={count} title={title} examples={['foo']} />)).toMatchSnapshot();
render(<CountCard count={count} title={title} examples={examples} />);

expect(screen.getByText(count)).toBeInTheDocument();
expect(screen.getByText(title)).toBeInTheDocument();
expect(screen.getByText(examples[0])).toBeInTheDocument();
});
});

This file was deleted.

This file was deleted.