Skip to content

Commit 5f74686

Browse files
authored
feat(unit-tests): migrate from enzyme to rtl COMPASS-10349 (#7840)
* feat(unit-tests): migrate from enzyme to rtl * chore: fix linter issues * refactor: use getByRole and getByLabelText queries instead of getByTestId where possible * fix: test assertion * fix: test assertion on table view * fix: remove unused deps
1 parent f5c796f commit 5f74686

14 files changed

Lines changed: 1614 additions & 2634 deletions

package-lock.json

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-crud/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@
5454
"@mongodb-js/prettier-config-compass": "^1.2.9",
5555
"@mongodb-js/testing-library-compass": "^1.5.2",
5656
"@mongodb-js/tsconfig-compass": "^1.2.14",
57-
"@types/enzyme": "^3.10.14",
5857
"@types/reflux": "^6.4.3",
5958
"chai": "^4.1.2",
6059
"chai-as-promised": "^7.1.1",
6160
"depcheck": "^1.4.1",
6261
"electron": "^37.10.3",
6362
"electron-mocha": "^12.2.0",
64-
"enzyme": "^3.11.0",
6563
"mocha": "^10.2.0",
6664
"mongodb-instance-model": "^12.67.0",
6765
"nyc": "^15.1.0",

packages/compass-crud/src/components/document-list-view.spec.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
3-
import type { ReactWrapper } from 'enzyme';
2+
import { render, screen, cleanup } from '@mongodb-js/testing-library-compass';
43
import HadronDocument from 'hadron-document';
54
import { expect } from 'chai';
65

76
import DocumentListView from './document-list-view';
8-
import { CompassComponentsProvider } from '@mongodb-js/compass-components';
97

108
describe('<DocumentListView />', function () {
9+
afterEach(cleanup);
10+
1111
describe('#render', function () {
1212
context('when the documents have objects for ids', function () {
13-
const docs = [{ _id: { name: 'test-1' } }, { _id: { name: 'test-2' } }];
14-
const hadronDocs = docs.map((doc) => new HadronDocument(doc));
15-
let component: ReactWrapper;
16-
beforeEach(function () {
17-
component = mount(
13+
it('renders all the documents', function () {
14+
const docs = [{ _id: { name: 'test-1' } }, { _id: { name: 'test-2' } }];
15+
const hadronDocs = docs.map((doc) => new HadronDocument(doc));
16+
17+
render(
1818
<DocumentListView
1919
docs={hadronDocs}
2020
isEditable={false}
2121
isTimeSeries={false}
22-
/>,
23-
{ wrappingComponent: CompassComponentsProvider }
22+
/>
2423
);
25-
});
2624

27-
afterEach(function () {
28-
component?.unmount();
29-
});
30-
31-
it('renders all the documents', function () {
32-
const wrapper = component.find('[data-testid="readonly-document"]');
33-
expect(wrapper).to.have.length(2);
25+
const documents = screen.getAllByTestId('readonly-document');
26+
expect(documents).to.have.length(2);
3427
});
3528
});
3629
});

0 commit comments

Comments
 (0)