Skip to content

Commit

Permalink
Replace assert with expect
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw committed Feb 28, 2020
1 parent f34f229 commit 8760d01
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
12 changes: 6 additions & 6 deletions packages/ra-core/src/core/RoutesWithLayout.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -34,7 +33,7 @@ describe('<RoutesWithLayout>', () => {
</Provider>
);

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', () => {
Expand All @@ -48,7 +47,7 @@ describe('<RoutesWithLayout>', () => {
</Provider>
);

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', () => {
Expand All @@ -64,8 +63,8 @@ describe('<RoutesWithLayout>', () => {
</Provider>
);

assert.notEqual(queryByText('Default'), null);
assert.equal(queryByText('Resource'), null);
expect(queryByText('Default')).not.toBeNull();
expect(queryByText('Resource')).toBeNull();
});

it('should accept custom routes', () => {
Expand All @@ -83,6 +82,7 @@ describe('<RoutesWithLayout>', () => {
</MemoryRouter>
</Provider>
);
assert.notEqual(queryByText('Custom'), null);

expect(queryByText('Custom')).not.toBeNull();
});
});
9 changes: 4 additions & 5 deletions packages/ra-core/src/form/FormField.spec.tsx
Original file line number Diff line number Diff line change
@@ -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('<FormField>', () => {
Expand All @@ -22,7 +21,7 @@ describe('<FormField>', () => {
);
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 <Field /> component if the field has an input', () => {
Expand All @@ -40,6 +39,6 @@ describe('<FormField>', () => {
);
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');
});
});
5 changes: 2 additions & 3 deletions packages/ra-ui-materialui/src/field/FunctionField.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import assert from 'assert';
import { render, cleanup } from '@testing-library/react';
import FunctionField from './FunctionField';

Expand All @@ -11,7 +10,7 @@ describe('<FunctionField />', () => {
const { queryByText } = render(
<FunctionField record={record} render={r => r.foo.substr(0, 2)} />
);
assert.notEqual(queryByText('ba'), null);
expect(queryByText('ba')).not.toBeNull();
});

it('should use custom className', () => {
Expand All @@ -22,6 +21,6 @@ describe('<FunctionField />', () => {
className="foo"
/>
);
assert.ok(queryByText('bar').classList.contains('foo'));
expect(queryByText('bar').classList).toContain('foo');
});
});
9 changes: 5 additions & 4 deletions packages/ra-ui-materialui/src/list/DatagridCell.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import React from 'react';
import PropTypes from 'prop-types';
import { render, cleanup } from '@testing-library/react';
Expand All @@ -15,6 +14,8 @@ const renderWithTable = element =>
);

describe('<DatagridCell />', () => {
afterEach(cleanup);

const Field = ({ basePath }) => <div>{basePath}</div>;
Field.propTypes = {
type: PropTypes.string,
Expand All @@ -29,20 +30,20 @@ describe('<DatagridCell />', () => {
const { getByRole } = renderWithTable(
<DatagridCell field={<Field />} />
);
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(
<DatagridCell basePath="default" field={<Field />} />
);
assert.notEqual(queryByText('default'), null);
expect(queryByText('default')).not.toBeNull();
});

it('should allow to overwrite the `basePath` field', () => {
const { queryByText } = renderWithTable(
<DatagridCell basePath="default" field={<Field basePath="new" />} />
);
assert.notEqual(queryByText('new'), null);
expect(queryByText('new')).not.toBeNull();
});
});
29 changes: 13 additions & 16 deletions packages/ra-ui-materialui/src/list/SingleFieldList.spec.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,8 +33,8 @@ describe('<SingleFieldList />', () => {
</SingleFieldList>
);
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',
]);
Expand All @@ -56,8 +55,8 @@ describe('<SingleFieldList />', () => {
</SingleFieldList>
);
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',
]);
Expand All @@ -79,9 +78,8 @@ describe('<SingleFieldList />', () => {
</SingleFieldList>
);
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();
Expand All @@ -105,8 +103,8 @@ describe('<SingleFieldList />', () => {
);

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',
]);
Expand All @@ -129,9 +127,8 @@ describe('<SingleFieldList />', () => {
</SingleFieldList>
);
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();
Expand All @@ -155,8 +152,8 @@ describe('<SingleFieldList />', () => {
);

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();
});
});

0 comments on commit 8760d01

Please sign in to comment.