From 5e8f51b29fccfb7d19d53854f3472f7370593ebf Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Mon, 29 Jun 2020 20:58:07 +0900 Subject: Replace to testing-library from enzyme (#14152) --- .../mastodon/components/__tests__/button-test.js | 10 +++++----- .../features/ui/components/__tests__/column-test.js | 15 +++++++-------- app/javascript/mastodon/test_setup.js | 6 +----- 3 files changed, 13 insertions(+), 18 deletions(-) (limited to 'app/javascript') diff --git a/app/javascript/mastodon/components/__tests__/button-test.js b/app/javascript/mastodon/components/__tests__/button-test.js index 160cd3cbc..f5a649f70 100644 --- a/app/javascript/mastodon/components/__tests__/button-test.js +++ b/app/javascript/mastodon/components/__tests__/button-test.js @@ -1,4 +1,4 @@ -import { shallow } from 'enzyme'; +import { render, fireEvent, screen } from '@testing-library/react'; import React from 'react'; import renderer from 'react-test-renderer'; import Button from '../button'; @@ -21,16 +21,16 @@ describe('); + fireEvent.click(screen.getByText('button')); expect(handler.mock.calls.length).toEqual(1); }); it('does not handle click events if props.disabled given', () => { const handler = jest.fn(); - const button = shallow(); + fireEvent.click(screen.getByText('button')); expect(handler.mock.calls.length).toEqual(0); }); diff --git a/app/javascript/mastodon/features/ui/components/__tests__/column-test.js b/app/javascript/mastodon/features/ui/components/__tests__/column-test.js index d2791ce08..a56859be0 100644 --- a/app/javascript/mastodon/features/ui/components/__tests__/column-test.js +++ b/app/javascript/mastodon/features/ui/components/__tests__/column-test.js @@ -1,25 +1,24 @@ +import { render, fireEvent, screen } from '@testing-library/react'; import React from 'react'; -import { mount } from 'enzyme'; import Column from '../column'; -import ColumnHeader from '../column_header'; describe('', () => { describe(' click handler', () => { it('runs the scroll animation if the column contains scrollable content', () => { - const wrapper = mount( + const scrollToMock = jest.fn(); + const { container } = render(
, ); - const scrollToMock = jest.fn(); - wrapper.find(Column).find('.scrollable').getDOMNode().scrollTo = scrollToMock; - wrapper.find(ColumnHeader).find('button').simulate('click'); + container.querySelector('.scrollable').scrollTo = scrollToMock; + fireEvent.click(screen.getByText('notifications')); expect(scrollToMock).toHaveBeenCalledWith({ behavior: 'smooth', top: 0 }); }); it('does not try to scroll if there is no scrollable content', () => { - const wrapper = mount(); - wrapper.find(ColumnHeader).find('button').simulate('click'); + render(); + fireEvent.click(screen.getByText('notifications')); }); }); }); diff --git a/app/javascript/mastodon/test_setup.js b/app/javascript/mastodon/test_setup.js index 80148379b..666127af3 100644 --- a/app/javascript/mastodon/test_setup.js +++ b/app/javascript/mastodon/test_setup.js @@ -1,5 +1 @@ -import { configure } from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -const adapter = new Adapter(); -configure({ adapter }); +import '@testing-library/jest-dom/extend-expect'; -- cgit