-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathaudit.unit.test.ts
More file actions
81 lines (75 loc) · 2.31 KB
/
audit.unit.test.ts
File metadata and controls
81 lines (75 loc) · 2.31 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
79
80
81
import { describe, expect, it } from 'vitest';
import { type Audit, auditSchema, pluginAuditsSchema } from './audit.js';
describe('auditSchema', () => {
it('should accept a valid audit with all information', () => {
expect(() =>
auditSchema.parse({
slug: 'no-conditionals-in-tests',
title: 'No conditional logic is used in tests.',
description: 'Conditional logic does not produce stable results.',
docsUrl:
'https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-conditional-in-test.md',
} satisfies Audit),
).not.toThrow();
});
it('should accept a valid audit with minimum information', () => {
expect(() =>
auditSchema.parse({
slug: 'jest-unit-test-results',
title: 'Jest unit tests results.',
} satisfies Audit),
).not.toThrow();
});
it('should ignore invalid docs URL', () => {
expect(
auditSchema.parse({
slug: 'consistent-test-it',
title: 'Use a consistent test function.',
docsUrl: 'invalid-url',
} satisfies Audit),
).toEqual<Audit>({
slug: 'consistent-test-it',
title: 'Use a consistent test function.',
docsUrl: '',
});
});
});
describe('pluginAuditsSchema', () => {
it('should parse a valid audit array', () => {
expect(() =>
pluginAuditsSchema.parse([
{
slug: 'consistent-test-it',
title: 'Use a consistent test function.',
},
{
slug: 'jest-unit-test-results',
title: 'Jest unit tests results.',
},
] satisfies Audit[]),
).not.toThrow();
});
it('should throw for an empty array', () => {
expect(() => pluginAuditsSchema.parse([])).toThrow('too_small');
});
it('should throw for duplicate audits', () => {
expect(() =>
pluginAuditsSchema.parse([
{
slug: 'consistent-test-it',
title: 'Use a consistent test function.',
},
{
slug: 'jest-unit-test-results',
title: 'Jest unit tests results.',
},
{
slug: 'jest-unit-test-results',
title: 'Jest unit tests results.',
},
] satisfies Audit[]),
).toThrow(
String.raw`Audit slugs must be unique, but received duplicates: \"jest-unit-test-results\"`,
);
});
});