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

[BC Break] Remove ra-test #7148

Merged
merged 11 commits into from
Jan 27, 2022
Merged

[BC Break] Remove ra-test #7148

merged 11 commits into from
Jan 27, 2022

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Jan 27, 2022

You no longer need a special package to unit test your components. The react-admin package provides all you need.

If you used TestContext from 'ra-test', use AdminContext instead:

import React from 'react';
-import { TestContext } from 'ra-test';
+import { AdminContext } from 'react-admin';
import { render, screen } from '@testing-library/react';

import MyComponent from './MyComponent';

test('<MyComponent>', async () => {
    render(
-       <TestContext>
+       <AdminContext>
            <MyComponent />
-       </TestContext>
+       </AdminContext>
    );
    const items = await screen.findAllByText(/Item #[0-9]: /)
    expect(items).toHaveLength(10)
})

UPGRADE.md Outdated Show resolved Hide resolved
docs/UnitTesting.md Outdated Show resolved Hide resolved
docs/UnitTesting.md Outdated Show resolved Hide resolved
docs/UnitTesting.md Outdated Show resolved Hide resolved
docs/UnitTesting.md Outdated Show resolved Hide resolved
docs/UnitTesting.md Outdated Show resolved Hide resolved
docs/UnitTesting.md Outdated Show resolved Hide resolved
docs/UnitTesting.md Outdated Show resolved Hide resolved
Copy link
Contributor

@WiXSL WiXSL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnitTesting.md

Fix occurrences of getOne: jest.fn().resolve with getOne: Promise.resolve

Copy link
Contributor

@WiXSL WiXSL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnitTesting.md

Fix occurrences of

const tabs = testUtils.queryByRole('tab'); expect(tabs.length).toEqual with
const tabs = testUtils.queryAllByRole('tab'); expect(tabs).toHaveLength

Co-authored-by: Aníbal Svarcas <WiXSL@users.noreply.github.com>
docs/UnitTesting.md Outdated Show resolved Hide resolved
Co-authored-by: Aníbal Svarcas <WiXSL@users.noreply.github.com>
## Spying on the store 'dispatch'

If you are using `useDispatch` within your components, it is likely you will want to test that actions have been dispatched with the correct arguments. You can return the `store` being used within the tests using a `renderProp`.
**Tip**: If you're using TypeScript, the compiler will complain about missing methods in the data provider above. You can remove these warnings by using the `testDataProvider` helper:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, TS will still complain when using the testDataProvider because of the Record type. We have some work to do on this subject

@djhi djhi merged commit 4d3bb37 into next Jan 27, 2022
@djhi djhi deleted the kill-ra-test branch January 27, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants