diff --git a/packages/ra-core/src/core/RoutesWithLayout.spec.tsx b/packages/ra-core/src/core/RoutesWithLayout.spec.tsx index 6f68767f91d..17c0f30ae26 100644 --- a/packages/ra-core/src/core/RoutesWithLayout.spec.tsx +++ b/packages/ra-core/src/core/RoutesWithLayout.spec.tsx @@ -3,7 +3,6 @@ import { Route, MemoryRouter } from 'react-router-dom'; import { createStore } from 'redux'; import { Provider } from 'react-redux'; import { render, cleanup } from '@testing-library/react'; -import assert from 'assert'; import RoutesWithLayout from './RoutesWithLayout'; @@ -34,7 +33,7 @@ describe('', () => { ); - assert.notEqual(queryByText('Dashboard'), null); + expect(queryByText('Dashboard')).not.toBeNull(); }); it('should show the first resource on / when there is only one resource and no dashboard', () => { @@ -48,7 +47,7 @@ describe('', () => { ); - assert.notEqual(queryByText('Default'), null); + expect(queryByText('Default')).not.toBeNull(); }); it('should show the first resource on / when there are multiple resource and no dashboard', () => { @@ -64,8 +63,8 @@ describe('', () => { ); - assert.notEqual(queryByText('Default'), null); - assert.equal(queryByText('Resource'), null); + expect(queryByText('Default')).not.toBeNull(); + expect(queryByText('Resource')).toBeNull(); }); it('should accept custom routes', () => { @@ -83,6 +82,7 @@ describe('', () => { ); - assert.notEqual(queryByText('Custom'), null); + + expect(queryByText('Custom')).not.toBeNull(); }); }); diff --git a/packages/ra-core/src/form/FormField.spec.tsx b/packages/ra-core/src/form/FormField.spec.tsx index 449a03b34fe..93e60a9003f 100644 --- a/packages/ra-core/src/form/FormField.spec.tsx +++ b/packages/ra-core/src/form/FormField.spec.tsx @@ -1,7 +1,6 @@ -import assert from 'assert'; -import { render, fireEvent, cleanup } from '@testing-library/react'; -import { Form } from 'react-final-form'; import React from 'react'; +import { Form } from 'react-final-form'; +import { render, fireEvent, cleanup } from '@testing-library/react'; import FormField from './FormField'; describe('', () => { @@ -22,7 +21,7 @@ describe('', () => { ); const input = getByRole('textbox'); fireEvent.change(input, { target: { value: 'Lorem' } }); - assert.equal(formApi.getState().values.title, 'Lorem'); + expect(formApi.getState().values.title).toEqual('Lorem'); }); it('should not render a component if the field has an input', () => { @@ -40,6 +39,6 @@ describe('', () => { ); const input = getByRole('textbox'); fireEvent.change(input, { target: { value: 'Lorem' } }); - assert.notEqual(formApi.getState().values.title, 'Lorem'); + expect(formApi.getState().values.title).not.toEqual('Lorem'); }); }); diff --git a/packages/ra-ui-materialui/src/field/FunctionField.spec.js b/packages/ra-ui-materialui/src/field/FunctionField.spec.js index 26e99fa6e20..16ad3a897f5 100644 --- a/packages/ra-ui-materialui/src/field/FunctionField.spec.js +++ b/packages/ra-ui-materialui/src/field/FunctionField.spec.js @@ -1,5 +1,4 @@ import React from 'react'; -import assert from 'assert'; import { render, cleanup } from '@testing-library/react'; import FunctionField from './FunctionField'; @@ -11,7 +10,7 @@ describe('', () => { const { queryByText } = render( r.foo.substr(0, 2)} /> ); - assert.notEqual(queryByText('ba'), null); + expect(queryByText('ba')).not.toBeNull(); }); it('should use custom className', () => { @@ -22,6 +21,6 @@ describe('', () => { className="foo" /> ); - assert.ok(queryByText('bar').classList.contains('foo')); + expect(queryByText('bar').classList).toContain('foo'); }); }); diff --git a/packages/ra-ui-materialui/src/list/DatagridCell.spec.js b/packages/ra-ui-materialui/src/list/DatagridCell.spec.js index d3aa6128a0c..8554d42eacf 100644 --- a/packages/ra-ui-materialui/src/list/DatagridCell.spec.js +++ b/packages/ra-ui-materialui/src/list/DatagridCell.spec.js @@ -1,4 +1,3 @@ -import assert from 'assert'; import React from 'react'; import PropTypes from 'prop-types'; import { render, cleanup } from '@testing-library/react'; @@ -15,6 +14,8 @@ const renderWithTable = element => ); describe('', () => { + afterEach(cleanup); + const Field = ({ basePath }) =>
{basePath}
; Field.propTypes = { type: PropTypes.string, @@ -29,20 +30,20 @@ describe('', () => { const { getByRole } = renderWithTable( } /> ); - assert.equal(getByRole('cell').className, 'MuiTableCell-root'); + expect(getByRole('cell').className).toEqual('MuiTableCell-root'); }); it('should pass the Datagrid basePath by default', () => { const { queryByText } = renderWithTable( } /> ); - assert.notEqual(queryByText('default'), null); + expect(queryByText('default')).not.toBeNull(); }); it('should allow to overwrite the `basePath` field', () => { const { queryByText } = renderWithTable( } /> ); - assert.notEqual(queryByText('new'), null); + expect(queryByText('new')).not.toBeNull(); }); }); diff --git a/packages/ra-ui-materialui/src/list/SingleFieldList.spec.js b/packages/ra-ui-materialui/src/list/SingleFieldList.spec.js index 658f72327d0..61666eee390 100644 --- a/packages/ra-ui-materialui/src/list/SingleFieldList.spec.js +++ b/packages/ra-ui-materialui/src/list/SingleFieldList.spec.js @@ -1,5 +1,4 @@ import React from 'react'; -import assert from 'assert'; import { render, cleanup } from '@testing-library/react'; import { createMemoryHistory } from 'history'; import { Router } from 'react-router-dom'; @@ -34,8 +33,8 @@ describe('', () => { ); const linkElements = queryAllByRole('link'); - assert.equal(linkElements.length, 2); - assert.deepEqual(linkElements.map(link => link.getAttribute('href')), [ + expect(linkElements).toHaveLength(2); + expect(linkElements.map(link => link.getAttribute('href'))).toEqual([ '/posts/1', '/posts/2', ]); @@ -56,8 +55,8 @@ describe('', () => { ); const linkElements = queryAllByRole('link'); - assert.equal(linkElements.length, 2); - assert.deepEqual(linkElements.map(link => link.getAttribute('href')), [ + expect(linkElements).toHaveLength(2); + expect(linkElements.map(link => link.getAttribute('href'))).toEqual([ '/posts/1', '/posts/2', ]); @@ -79,9 +78,8 @@ describe('', () => { ); const linkElements = queryAllByRole('link'); - assert.equal(linkElements.length, 2); - assert.deepEqual( - linkElements.map(link => link.getAttribute('href')), + expect(linkElements).toHaveLength(2); + expect(linkElements.map(link => link.getAttribute('href'))).toEqual( [`/${action}/1`, `/${action}/2`] ); cleanup(); @@ -105,8 +103,8 @@ describe('', () => { ); const linkElements = queryAllByRole('link'); - assert.equal(linkElements.length, 2); - assert.deepEqual(linkElements.map(link => link.getAttribute('href')), [ + expect(linkElements).toHaveLength(2); + expect(linkElements.map(link => link.getAttribute('href'))).toEqual([ '/prefix/bar/1/show', '/prefix/bar/2/show', ]); @@ -129,9 +127,8 @@ describe('', () => { ); const linkElements = queryAllByRole('link'); - assert.equal(linkElements.length, 2); - assert.deepEqual( - linkElements.map(link => link.getAttribute('href')), + expect(linkElements).toHaveLength(2); + expect(linkElements.map(link => link.getAttribute('href'))).toEqual( [`/${action}/1/show`, `/${action}/2/show`] ); cleanup(); @@ -155,8 +152,8 @@ describe('', () => { ); const linkElements = queryAllByRole('link'); - assert.equal(linkElements.length, 0); - assert.notEqual(queryByText('foo'), null); - assert.notEqual(queryByText('bar'), null); + expect(linkElements).toHaveLength(0); + expect(queryByText('foo')).not.toBeNull(); + expect(queryByText('bar')).not.toBeNull(); }); });