Skip to content

Commit

Permalink
Merge pull request #3489 from marmelab/migrate-to-testing-library
Browse files Browse the repository at this point in the history
[RFR] Update to @testing-library/react
  • Loading branch information
Kmaschta authored Aug 6, 2019
2 parents cabecb1 + 8358754 commit 8ea6667
Show file tree
Hide file tree
Showing 58 changed files with 100 additions and 85 deletions.
2 changes: 1 addition & 1 deletion packages/ra-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"react-redux": "^7.1.0",
"react-router": "^5.0.1",
"react-router-dom": "^5.0.1",
"react-testing-library": "^7.0.0",
"@testing-library/react": "^8.0.7",
"recompose": "~0.26.0",
"redux": "^3.7.2 || ^4.0.3",
"redux-saga": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/CoreAdminRouter.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { cleanup, wait } from 'react-testing-library';
import { cleanup, wait } from '@testing-library/react';
import expect from 'expect';
import { Router, Route } from 'react-router-dom';
import { createMemoryHistory } from 'history';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/Resource.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { cleanup, wait } from 'react-testing-library';
import { cleanup, wait } from '@testing-library/react';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/auth/Authenticated.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';

import Authenticated from './Authenticated';
import AuthContext from './AuthContext';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/auth/useAuth.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { cleanup, wait } from 'react-testing-library';
import { cleanup, wait } from '@testing-library/react';
import { replace } from 'connected-react-router';

import useAuth from './useAuth';
Expand Down
5 changes: 2 additions & 3 deletions packages/ra-core/src/auth/usePermissions.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { cleanup, wait } from 'react-testing-library';
import { cleanup, wait } from '@testing-library/react';

import usePermissions from './usePermissions';
import AuthContext from './AuthContext';
Expand Down Expand Up @@ -43,13 +43,12 @@ describe('usePermissions', () => {

it('should return the permissions after a tick', async () => {
const authProvider = () => Promise.resolve('admin');
const { queryByText, debug } = renderWithRedux(
const { queryByText } = renderWithRedux(
<AuthContext.Provider value={authProvider}>
<UsePermissions>{stateInpector}</UsePermissions>
</AuthContext.Provider>
);
await wait();
debug();
expect(queryByText('LOADING')).toBeNull();
expect(queryByText('LOADED')).not.toBeNull();
expect(queryByText('PERMISSIONS: admin')).not.toBeNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';

import ReferenceArrayFieldController from './ReferenceArrayFieldController';
import renderWithRedux from '../../util/renderWithRedux';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';

import ReferenceFieldController from './ReferenceFieldController';
import renderWithRedux from '../../util/renderWithRedux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('<ReferenceManyFieldController />', () => {
const { dispatch } = renderWithRedux(
<ReferenceManyFieldController
resource="foo"
source="items"
reference="bar"
target="foo_id"
basePath=""
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('<ReferenceManyFieldController />', () => {
id: undefined,
pagination: { page: 1, perPage: 25 },
sort: { field: 'id', order: 'DESC' },
source: undefined,
source: 'items',
target: 'foo_id',
},
type: 'RA/CRUD_GET_MANY_REFERENCE',
Expand All @@ -75,6 +76,7 @@ describe('<ReferenceManyFieldController />', () => {
target="fooId"
basePath=""
record={{
id: 'fooId',
source: 'barId',
}}
source="source"
Expand Down Expand Up @@ -114,6 +116,7 @@ describe('<ReferenceManyFieldController />', () => {
target="fooId"
basePath=""
record={{
id: 'fooId',
source: 'barId',
}}
source="source"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';
import omit from 'lodash/omit';

import renderWithRedux from '../../util/renderWithRedux';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import renderHook from '../../util/renderHook';
import useMatchingReferences from './useGetMatchingReferences';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';

describe('useMatchingReferences', () => {
const defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useEditController.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { act, cleanup } from 'react-testing-library';
import { act, cleanup } from '@testing-library/react';

import EditController from './EditController';
import renderWithRedux from '../util/renderWithRedux';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useFilterState.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import renderHook from '../util/renderHook';
import useFilterState from './useFilterState';
import { act } from 'react-testing-library';
import { act } from '@testing-library/react';

describe('useFilterState', () => {
it('should initialize filterState with default filter', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useListController.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { fireEvent, cleanup } from 'react-testing-library';
import { fireEvent, cleanup } from '@testing-library/react';
import lolex from 'lolex';
import TextField from '@material-ui/core/TextField/TextField';

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/usePaginationState.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import renderHook from '../util/renderHook';
import usePaginationState from './usePaginationState';
import { act } from 'react-testing-library';
import { act } from '@testing-library/react';

describe('usePaginationState', () => {
it('should initialize pagination state with default', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useReference.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import renderHook from '../util/renderHook';
import useReference from './useReference';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';

describe('useReference', () => {
const defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useSortState.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import renderHook from '../util/renderHook';
import useSortState, { defaultSort } from './useSortState';
import { act } from 'react-testing-library';
import { act } from '@testing-library/react';

describe('useSortState', () => {
it('should initialize sortState with default sort', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/dataProvider/Mutation.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';
import expect from 'expect';
import Mutation from './Mutation';
import renderWithRedux from '../util/renderWithRedux';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/dataProvider/Query.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
act,
// @ts-ignore
waitForDomChange,
} from 'react-testing-library';
} from '@testing-library/react';
import expect from 'expect';
import Query from './Query';
import CoreAdmin from '../CoreAdmin';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/dataProvider/useMutation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
cleanup,
fireEvent,
waitForDomChange,
} from 'react-testing-library';
} from '@testing-library/react';
import expect from 'expect';
import Mutation from './Mutation';
import CoreAdmin from '../CoreAdmin';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/form/ValidationError.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';

import ValidationError from './ValidationError';
import { TranslationProvider } from '../i18n';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/i18n/useTranslate.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';

import useTranslate from './useTranslate';
import { TranslationContext } from './TranslationContext';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/util/FieldTitle.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import expect from 'expect';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';
import React from 'react';

import { FieldTitle } from './FieldTitle';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/util/TestContext.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import expect from 'expect';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';
import React from 'react';

import TestContext, { defaultStore } from './TestContext';
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/util/renderHook.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, RenderResult } from 'react-testing-library';
import { render, RenderResult } from '@testing-library/react';

import renderWithRedux, { RenderWithReduxResult } from './renderWithRedux';

Expand All @@ -19,7 +19,7 @@ interface RenderHookWithReduxResult extends RenderWithReduxResult {
}

/**
* render given hook using react-testing-library and return hook value
* render given hook using @testing-library/react and return hook value
* @param hook the hook to render
* @param withRedux should we provide a redux context default to true
* @param reduxState optional initial state for redux context
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/util/renderWithRedux.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, RenderResult } from 'react-testing-library';
import { render, RenderResult } from '@testing-library/react';

import TestContext from './TestContext';

Expand All @@ -19,7 +19,7 @@ export interface RenderWithReduxResult extends RenderResult {
* @param {ReactNode} component: The component you want to test in jsx
* @param {Object} initialstate: Optional initial state of the redux store
* @return {{ dispatch, reduxStore, ...rest }} helper function to test rendered component.
* Same as react-testing-library render method with added dispatch and reduxStore helper
* Same as @testing-library/react render method with added dispatch and reduxStore helper
* dispatch: spy on the redux stroe dispatch method
* reduxStore: the redux store used by the tested component
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-input-rich-text/src/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import debounce from 'lodash/debounce';
import { render, fireEvent, waitForElement } from 'react-testing-library';
import { render, fireEvent, waitForElement } from '@testing-library/react';

import { RichTextInput } from './index';

Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"react": "~16.8.0",
"react-dom": "~16.8.0",
"react-test-renderer": "~16.8.6",
"react-testing-library": "^7.0.0",
"@testing-library/react": "^8.0.7",
"rimraf": "^2.6.3"
},
"peerDependencies": {
Expand Down Expand Up @@ -65,6 +65,6 @@
"react-router-dom": "^5.0.1",
"react-transition-group": "^2.2.1",
"recompose": "~0.26.0",
"redux": "^3.7.2 || ^4.0.0"
"redux": "^3.7.2 || ^4.0.3"
}
}
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/button/SaveButton.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, cleanup, fireEvent } from 'react-testing-library';
import { render, cleanup, fireEvent } from '@testing-library/react';
import React from 'react';

import { SaveButton } from './SaveButton';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/detail/Create.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';
import { renderWithRedux } from 'ra-core';

import Create from './Create';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/detail/Edit.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';
import { renderWithRedux } from 'ra-core';

import Edit from './Edit';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/detail/Show.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';
import { renderWithRedux } from 'ra-core';

import Show from './Show';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/field/BooleanField.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import expect from 'expect';
import { BooleanField } from './BooleanField';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';

const defaultProps = {
record: { published: true },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';
import { MemoryRouter } from 'react-router';

import { ReferenceArrayFieldView } from './ReferenceArrayField';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/field/ReferenceField.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import { renderWithRedux } from 'ra-core';

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/field/SelectField.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';

import { renderWithRedux } from 'ra-core';
import { SelectField } from './SelectField';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/form/SimpleForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';
import React from 'react';
import { renderWithRedux } from 'ra-core';

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cleanup } from 'react-testing-library';
import { cleanup } from '@testing-library/react';
import React, { createElement } from 'react';
import { MemoryRouter } from 'react-router';
import { renderWithRedux } from 'ra-core';
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/input/ArrayInput.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';
import { Form } from 'react-final-form';
import arrayMutators from 'final-form-arrays';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
fireEvent,
render,
waitForDomChange,
} from 'react-testing-library';
} from '@testing-library/react';

import { AutocompleteArrayInput } from './AutocompleteArrayInput';

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/input/BooleanInput.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';

import { BooleanInput } from './BooleanInput';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import expect from 'expect';
import { CheckboxGroupInput } from './CheckboxGroupInput';
import { render, cleanup } from 'react-testing-library';
import { render, cleanup } from '@testing-library/react';

describe('<CheckboxGroupInput />', () => {
const defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/input/DateInput.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import expect from 'expect';
import { render, fireEvent, cleanup } from 'react-testing-library';
import { render, fireEvent, cleanup } from '@testing-library/react';

import { DateInput } from './DateInput';

Expand Down
Loading

0 comments on commit 8ea6667

Please sign in to comment.