-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconfig.unit.test.ts
More file actions
78 lines (66 loc) · 2.21 KB
/
config.unit.test.ts
File metadata and controls
78 lines (66 loc) · 2.21 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { axePluginOptionsSchema } from './config.js';
describe('axePluginOptionsSchema', () => {
it('should accept empty options object with default preset and timeout', () => {
const parsed = axePluginOptionsSchema.parse({});
expect(parsed.preset).toBe('wcag21aa');
expect(parsed.timeout).toBe(30_000);
});
it.each(['wcag21aa', 'wcag22aa', 'best-practice', 'all'])(
'should validate %j as a valid preset value',
preset => {
expect(() => axePluginOptionsSchema.parse({ preset })).not.toThrow();
},
);
it('should accept setupScript as a file path', () => {
expect(() =>
axePluginOptionsSchema.parse({ setupScript: 'src/axe-setup.js' }),
).not.toThrow();
});
it('should accept scoreTargets as a number between 0 and 1', () => {
expect(() =>
axePluginOptionsSchema.parse({ scoreTargets: 0.99 }),
).not.toThrow();
});
it('should accept scoreTargets as an audit-specific score map', () => {
expect(() =>
axePluginOptionsSchema.parse({
scoreTargets: { 'color-contrast': 0.99 },
}),
).not.toThrow();
});
it('should reject invalid preset values', () => {
expect(() => axePluginOptionsSchema.parse({ preset: 'wcag3aa' })).toThrow(
ZodError,
);
});
it('should reject scoreTargets values greater than 1', () => {
expect(() => axePluginOptionsSchema.parse({ scoreTargets: 1.5 })).toThrow(
ZodError,
);
});
it('should reject negative scoreTargets', () => {
expect(() => axePluginOptionsSchema.parse({ scoreTargets: -0.1 })).toThrow(
ZodError,
);
});
it('should accept custom timeout value', () => {
expect(axePluginOptionsSchema.parse({ timeout: 60_000 }).timeout).toBe(
60_000,
);
});
it('should reject non-positive timeout values', () => {
expect(() => axePluginOptionsSchema.parse({ timeout: 0 })).toThrow(
ZodError,
);
expect(() => axePluginOptionsSchema.parse({ timeout: -1000 })).toThrow(
ZodError,
);
});
it('should reject non-integer timeout values', () => {
expect(() => axePluginOptionsSchema.parse({ timeout: 1000.5 })).toThrow(
ZodError,
);
});
});