Skip to content

Commit 15aa3c6

Browse files
feat: refactor tests
1 parent 6984b24 commit 15aa3c6

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/courseware/course/sequence/sequence-navigation/SequenceNavigationTabs.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('Sequence Navigation Tabs', () => {
5454
const booyah = render(<SequenceNavigationTabs {...mockData} />, { wrapWithRouter: true });
5555

5656
// wait for links to appear so we aren't testing an empty div
57-
await screen.findAllByRole('link');
57+
await screen.findAllByRole('tabpanel');
5858

5959
container = booyah.container;
6060

src/generic/hooks.test.jsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ describe('Hooks', () => {
9898
test('should warn if element is not focusable', async () => {
9999
render(<TestComponent />);
100100

101-
const skipLink = screen.getByRole('link', { name: /skip to content/i });
101+
const skipLink = screen.getByTestId('skip-link');
102102
const targetContent = screen.getByTestId('target-content');
103103

104-
jest.spyOn(targetContent, 'focus').mockImplementationOnce(() => {
105-
throw new Error('focus is not a function');
104+
Object.defineProperty(targetContent, 'focus', {
105+
value: undefined,
106+
configurable: true,
106107
});
107108

108109
await userEvent.click(skipLink);
@@ -119,13 +120,20 @@ describe('Hooks', () => {
119120
});
120121

121122
test('should warn if target element is not found', async () => {
122-
render(<TestComponent />);
123+
const ComponentWithoutTarget = () => {
124+
useScrollToContent();
125+
return (
126+
<>
127+
<a href="#main-content" data-testid="skip-link">Skip to content</a>
128+
{/* Нет #main-content */}
129+
</>
130+
);
131+
};
132+
133+
render(<ComponentWithoutTarget />);
123134

124135
const skipLink = screen.getByRole('link', { name: /skip to content/i });
125136

126-
const targetElement = document.getElementById('main-content');
127-
targetElement?.parentNode?.removeChild(targetElement);
128-
129137
await userEvent.click(skipLink);
130138

131139
await waitFor(() => {

0 commit comments

Comments
 (0)