-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.test.jsx
More file actions
54 lines (43 loc) · 1.53 KB
/
index.test.jsx
File metadata and controls
54 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import NavBar from '..';
const Logo = () => <span>Node.js</span>;
describe('NavBar', () => {
it('uses a keyboard-accessible button to toggle the mobile navigation', async () => {
const user = userEvent.setup();
render(
<NavBar
as="a"
Logo={Logo}
pathname="/"
sidebarItemTogglerAriaLabel="Toggle navigation menu"
navItems={[
{ text: 'Learn', link: '/learn' },
{ text: 'About', link: '/about' },
]}
>
<a href="/search">Search</a>
</NavBar>
);
const menuButton = screen.getByRole('button', {
name: 'Toggle navigation menu',
});
const navigation = screen
.getByRole('navigation')
.querySelector('#navbar-navigation');
assert.ok(menuButton);
assert.ok(navigation);
assert.equal(menuButton.tagName, 'BUTTON');
assert.equal(menuButton.getAttribute('tabindex'), null);
assert.equal(menuButton.getAttribute('aria-expanded'), 'false');
assert.match(navigation.className, /\bhidden\b/);
await user.click(menuButton);
assert.equal(menuButton.getAttribute('aria-expanded'), 'true');
assert.match(navigation.className, /\bflex\b/);
await user.click(menuButton);
assert.equal(menuButton.getAttribute('aria-expanded'), 'false');
assert.match(navigation.className, /\bhidden\b/);
});
});