-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.mjs
44 lines (43 loc) · 1.28 KB
/
index.test.mjs
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
import { describe, expect, it } from 'vitest';
import { renderHook } from '@testing-library/react';
import { useCounter } from './index.mjs';
describe('index.mjs', () => {
describe('count', () => {
it('count is zero', function() {
const { result } = renderHook(useCounter);
expect(result.current.count).toBe(0);
});
it('can set initial value', function() {
const { result } = renderHook(() => useCounter(100));
expect(result.current.count).toBe(100);
});
});
describe('increment', function() {
it.each([
[1, 1],
[3, 3]
])('can increment', function(len, expected) {
const { result, rerender } = renderHook(useCounter);
expect(result.current.count).toBe(0);
for (let i = 0; i < len; i += 1) {
result.current.increment();
}
rerender();
expect(result.current.count).toBe(expected);
});
});
describe('decrement', function() {
it.each([
[1, -1],
[3, -3]
])('can decrement', function(len, expected) {
const { result, rerender } = renderHook(useCounter);
expect(result.current.count).toBe(0);
for (let i = 0; i < len; i += 1) {
result.current.decrement();
}
rerender();
expect(result.current.count).toBe(expected);
});
});
});