Skip to content

Commit 5c08a1d

Browse files
author
Daniel A. White
committed
fix more tests
1 parent f5a31c7 commit 5c08a1d

File tree

7 files changed

+991
-126
lines changed

7 files changed

+991
-126
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"enzyme-to-json": "^3.6.1",
8989
"eslint": "^8.4.1",
9090
"eslint-plugin-import": "^2.25.3",
91+
"eslint-plugin-jest": "^28.6.0",
9192
"eslint-plugin-prettier": "^5.1.3",
9293
"eslint-plugin-react": "^7.27.1",
9394
"eslint-plugin-react-hooks": "^4.3.0",

src/components/__tests__/TopLevelSchemaRow.spec.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import 'jest-enzyme';
1+
import '@testing-library/jest-dom';
22

33
import { RootNode } from '@stoplight/json-schema-tree';
4-
import { Icon } from '@stoplight/mosaic';
5-
import { mount } from 'enzyme';
4+
import { render } from '@testing-library/react';
65
import { JSONSchema4 } from 'json-schema';
76
import * as React from 'react';
7+
import { describe, expect, it } from 'vitest';
88

99
import { TopLevelSchemaRow } from '../SchemaRow/TopLevelSchemaRow';
1010
import { buildTree } from '../shared/__tests__/utils';
@@ -40,11 +40,10 @@ describe('resolving permission error', () => {
4040
};
4141

4242
tree = buildTree(schema);
43-
const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
44-
expect(wrapper.find(Icon).at(0)).toHaveProp('aria-label', `You do not have permission to view this reference`);
45-
expect(wrapper.find(Icon).at(1)).toHaveProp('aria-label', `You do not have permission to view this reference`);
46-
expect(wrapper.find(Icon).at(2)).not.toHaveProp('aria-label', `You do not have permission to view this reference`);
47-
expect(wrapper.find(Icon).at(3)).not.toHaveProp('aria-label', `You do not have permission to view this reference`);
43+
const wrapper = render(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
44+
const icons = wrapper.queryAllByLabelText('You do not have permission to view this reference');
45+
expect(icons).toHaveLength(2);
46+
4847
wrapper.unmount();
4948
});
5049

@@ -73,10 +72,9 @@ describe('resolving permission error', () => {
7372
};
7473

7574
tree = buildTree(schema);
76-
const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
77-
expect(wrapper.find(Icon).at(0)).toHaveProp('aria-label', `You do not have permission to view this reference`);
78-
expect(wrapper.find(Icon).at(1)).toHaveProp('aria-label', `You do not have permission to view this reference`);
79-
expect(wrapper.find(Icon).at(2)).toHaveProp('aria-label', `You do not have permission to view this reference`);
75+
const wrapper = render(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
76+
const icons = wrapper.queryAllByLabelText('You do not have permission to view this reference');
77+
expect(icons).toHaveLength(3);
8078
wrapper.unmount();
8179
});
8280

@@ -87,8 +85,10 @@ describe('resolving permission error', () => {
8785
'x-sl-internally-excluded': true,
8886
};
8987
tree = buildTree(schema);
90-
const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
91-
expect(wrapper.find(Icon).at(0)).toHaveProp('aria-label', `You do not have permission to view this reference`);
88+
const wrapper = render(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
89+
const icons = wrapper.queryAllByLabelText('You do not have permission to view this reference');
90+
expect(icons).toHaveLength(1);
91+
expect(icons[0]).toBeInTheDocument();
9292
wrapper.unmount();
9393
});
9494

@@ -126,10 +126,9 @@ describe('resolving permission error', () => {
126126
};
127127

128128
tree = buildTree(schema);
129-
const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
130-
expect(wrapper.find(Icon).at(1)).not.toHaveProp('title', `You do not have permission to view this reference`);
131-
expect(wrapper.find(Icon).at(2)).not.toHaveProp('title', `You do not have permission to view this reference`);
132-
expect(wrapper.find(Icon).at(3)).not.toHaveProp('title', `You do not have permission to view this reference`);
129+
const wrapper = render(<TopLevelSchemaRow schemaNode={tree.children[0]!} />);
130+
const icons = wrapper.queryAllByLabelText('You do not have permission to view this reference');
131+
expect(icons).toHaveLength(0);
133132
wrapper.unmount();
134133
});
135134
});

src/components/shared/__tests__/Properties.spec.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import 'jest-enzyme';
1+
import '@testing-library/jest-dom';
22

33
import { RegularNode } from '@stoplight/json-schema-tree';
44
import { Dictionary } from '@stoplight/types';
5-
import { shallow } from 'enzyme';
5+
import { render } from '@testing-library/react';
66
import * as React from 'react';
7+
import { beforeEach, describe, expect, it } from 'vitest';
78

89
import { Properties } from '../Properties';
910

@@ -22,11 +23,9 @@ describe('Properties component', () => {
2223
});
2324

2425
it('should render deprecated box', () => {
25-
const wrapper = shallow(
26-
<Properties deprecated={deprecated} required={false} validations={validations} />,
27-
).childAt(0);
26+
const wrapper = render(<Properties deprecated={deprecated} required={false} validations={validations} />);
2827

29-
expect(wrapper).toHaveText('deprecated');
28+
expect(wrapper.queryByText('deprecated')).toBeInTheDocument();
3029
});
3130
});
3231
});

0 commit comments

Comments
 (0)