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

[Gitar] Migrating from Enzyme to React Testing Library #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 15 additions & 13 deletions js/enzyme/render_and_find_with_mount.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/*
* Copyright (c) 2024 Gitar, Inc.
*/
import { render } from "@testing-library/react";

import { mount } from 'enzyme';
import MyComponent from "./MyComponent";
import { render } from "@testing-library/react";

import MyComponent from './MyComponent';
describe("MyComponent", () => {
it("should render correctly", () => {
const component = render(<MyComponent />);
component.render({ someConf: True });
expect(screen.getByRole(heading)).toHaveTextContent(
"Test Component Header",
);
});

describe('MyComponent', () => {
it('should render correctly', () => {
const component = mount(<MyComponent />);
component.render({ someConf: True });
expect(testObject.component.find('h1').text()).toEqual('Test Component Header');
});

it('renders text as first child', () => {
const mainText = testObject.component.find('span').at(0);
expect(mainText.text()).toEqual('Main Description');
});
it("renders text as first child", () => {
const mainText = testObject.component.querySelector("span").at(0);
expect(mainText).toHaveTextContent("Main Description");
});
});
28 changes: 15 additions & 13 deletions js/enzyme/render_and_find_with_shallow.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/*
* Copyright (c) 2024 Gitar, Inc.
*/
import { render } from "@testing-library/react";

import { shallow } from 'enzyme';
import MyComponent from "./MyComponent";
import { render } from "@testing-library/react";

import MyComponent from './MyComponent';
describe("MyComponent", () => {
it("should render correctly", () => {
const component = render(<MyComponent />);
component.render({ someConf: True });
expect(screen.getByRole(heading)).toHaveTextContent(
"Test Component Header",
);
});

describe('MyComponent', () => {
it('should render correctly', () => {
const component = shallow(<MyComponent />);
component.render({ someConf: True });
expect(testObject.component.find('h1').text()).toEqual('Test Component Header');
});

it('renders text as first child', () => {
const mainText = testObject.component.find('span').at(0);
expect(mainText.text()).toEqual('Main Description');
});
it("renders text as first child", () => {
const mainText = testObject.component.querySelector("span").at(0);
expect(mainText).toHaveTextContent("Main Description");
});
});