1
- import { deepStrictEqual , strictEqual } from 'assert'
2
- import { describe , it } from 'vitest'
1
+ import { describe , expect , it } from 'vitest'
3
2
import {
4
3
validate ,
5
4
string ,
@@ -13,20 +12,20 @@ import {
13
12
describe ( 'validate' , ( ) => {
14
13
it ( 'valid as helper' , ( ) => {
15
14
const S = string ( )
16
- deepStrictEqual ( validate ( 'valid' , S ) , [ undefined , 'valid' ] )
15
+ expect ( validate ( 'valid' , S ) ) . toStrictEqual ( [ undefined , 'valid' ] )
17
16
} )
18
17
19
18
it ( 'valid as method' , ( ) => {
20
19
const S = string ( )
21
- deepStrictEqual ( S . validate ( 'valid' ) , [ undefined , 'valid' ] )
20
+ expect ( S . validate ( 'valid' ) ) . toStrictEqual ( [ undefined , 'valid' ] )
22
21
} )
23
22
24
23
it ( 'invalid as helper' , ( ) => {
25
24
const S = string ( )
26
25
const [ err , value ] = validate ( 42 , S )
27
- strictEqual ( value , undefined )
28
- strictEqual ( err instanceof StructError , true )
29
- deepStrictEqual ( Array . from ( ( err as StructError ) . failures ( ) ) , [
26
+ expect ( value ) . toStrictEqual ( undefined )
27
+ expect ( err ) . toBeInstanceOf ( StructError )
28
+ expect ( Array . from ( ( err as StructError ) . failures ( ) ) ) . toStrictEqual ( [
30
29
{
31
30
value : 42 ,
32
31
key : undefined ,
@@ -43,9 +42,9 @@ describe('validate', () => {
43
42
it ( 'invalid as method' , ( ) => {
44
43
const S = string ( )
45
44
const [ err , value ] = S . validate ( 42 )
46
- strictEqual ( value , undefined )
47
- strictEqual ( err instanceof StructError , true )
48
- deepStrictEqual ( Array . from ( ( err as StructError ) . failures ( ) ) , [
45
+ expect ( value ) . toStrictEqual ( undefined )
46
+ expect ( err ) . toBeInstanceOf ( StructError )
47
+ expect ( Array . from ( ( err as StructError ) . failures ( ) ) ) . toStrictEqual ( [
49
48
{
50
49
value : 42 ,
51
50
key : undefined ,
@@ -62,17 +61,16 @@ describe('validate', () => {
62
61
it ( 'error message path' , ( ) => {
63
62
const S = object ( { author : object ( { name : string ( ) } ) } )
64
63
const [ err ] = S . validate ( { author : { name : 42 } } )
65
- strictEqual (
66
- ( err as StructError ) . message ,
64
+ expect ( err ?. message ) . toBe (
67
65
'At path: author.name -- Expected a string, but received: 42'
68
66
)
69
67
} )
70
68
71
69
it ( 'custom error message' , ( ) => {
72
70
const S = string ( )
73
71
const [ err ] = S . validate ( 42 , { message : 'Validation failed!' } )
74
- strictEqual ( err ?. message , 'Validation failed!' )
75
- strictEqual ( err ?. cause , 'Expected a string, but received: 42' )
72
+ expect ( err ?. message ) . toBe ( 'Validation failed!' )
73
+ expect ( err ?. cause ) . toBe ( 'Expected a string, but received: 42' )
76
74
} )
77
75
78
76
it ( 'early exit' , ( ) => {
@@ -91,8 +89,8 @@ describe('validate', () => {
91
89
92
90
const S = object ( { a : A , b : B } )
93
91
S . validate ( { a : null , b : null } )
94
- strictEqual ( ranA , true )
95
- strictEqual ( ranB , false )
92
+ expect ( ranA ) . toBe ( true )
93
+ expect ( ranB ) . toBe ( false )
96
94
} )
97
95
98
96
it ( 'refiners after children' , ( ) => {
@@ -109,7 +107,7 @@ describe('validate', () => {
109
107
} )
110
108
111
109
B . validate ( { a : null } )
112
- deepStrictEqual ( order , [ 'validator' , 'refiner' ] )
110
+ expect ( order ) . toStrictEqual ( [ 'validator' , 'refiner' ] )
113
111
} )
114
112
115
113
it ( 'refiners even if nested refiners fail' , ( ) => {
@@ -127,7 +125,7 @@ describe('validate', () => {
127
125
const [ error ] = B . validate ( { a : null } )
128
126
// Collect all failures. Ensures all validation runs.
129
127
error ?. failures ( )
130
- strictEqual ( ranOuterRefiner , true )
128
+ expect ( ranOuterRefiner ) . toBe ( true )
131
129
} )
132
130
133
131
it ( 'skips refiners if validators return errors' , ( ) => {
@@ -145,6 +143,6 @@ describe('validate', () => {
145
143
const [ error ] = B . validate ( { a : null } )
146
144
// Collect all failures. Ensures all validation runs.
147
145
error ?. failures ( )
148
- strictEqual ( ranRefiner , false )
146
+ expect ( ranRefiner ) . toBe ( false )
149
147
} )
150
148
} )
0 commit comments