-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathuseScrollSpy.test.mjs
More file actions
38 lines (30 loc) · 1.13 KB
/
useScrollSpy.test.mjs
File metadata and controls
38 lines (30 loc) · 1.13 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
import { strictEqual } from 'node:assert';
import { describe, it } from 'node:test';
import { getActiveSlug } from '../useScrollSpy.mjs';
describe('getActiveSlug', () => {
it('should return null for an empty entries array', () => {
strictEqual(getActiveSlug([]), null);
});
it('should return null when no entry is intersecting', () => {
const entries = [
{ isIntersecting: false, target: { id: 'intro' } },
{ isIntersecting: false, target: { id: 'usage' } },
];
strictEqual(getActiveSlug(entries), null);
});
it('should return the id of the first intersecting entry', () => {
const entries = [
{ isIntersecting: false, target: { id: 'intro' } },
{ isIntersecting: true, target: { id: 'usage' } },
{ isIntersecting: true, target: { id: 'api' } },
];
strictEqual(getActiveSlug(entries), 'usage');
});
it('should return the id when only one entry is intersecting', () => {
const entries = [
{ isIntersecting: false, target: { id: 'intro' } },
{ isIntersecting: true, target: { id: 'config' } },
];
strictEqual(getActiveSlug(entries), 'config');
});
});