-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathindex.dom.test.ts
60 lines (46 loc) · 1.48 KB
/
index.dom.test.ts
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
55
56
57
58
59
60
import {act, renderHook} from '@testing-library/react-hooks/dom';
import {describe, expect, it} from 'vitest';
import {useQueue} from '../index.js';
describe('useQueue', () => {
it('should be defined', () => {
expect(useQueue).toBeDefined();
});
it('should render', () => {
const {result} = renderHook(() => useQueue());
expect(result.error).toBeUndefined();
});
it('should accept an initial value', () => {
const {result} = renderHook(() => useQueue([0, 1, 2, 3]));
expect(result.current.items).toStrictEqual([0, 1, 2, 3]);
});
it('should remove the first value', () => {
const {result} = renderHook(() => useQueue([0, 1, 2, 3]));
act(() => {
const removed = result.current.remove();
expect(removed).toBe(0);
});
expect(result.current.first).toBe(1);
});
it('should return the length', () => {
const {result} = renderHook(() => useQueue([0, 1, 2, 3]));
expect(result.current.size).toBe(4);
});
it('should add a value to the end', () => {
const {result} = renderHook(() => useQueue([0, 1, 2, 3]));
act(() => {
result.current.add(4);
});
expect(result.current.last).toBe(4);
});
it('should return referentially stable functions', () => {
const {result} = renderHook(() => useQueue([0, 1, 2, 3]));
const remove1 = result.current.remove;
const add1 = result.current.add;
act(() => {
result.current.add(1);
result.current.remove();
});
expect(result.current.remove).toBe(remove1);
expect(result.current.add).toBe(add1);
});
});