1- import { assert } from 'vitest'
1+ import { assert , expect } from 'vitest'
22import { preventChanges } from './prevent-changes.js'
33import { clone } from '../../common/index.js'
44
@@ -15,17 +15,27 @@ describe('preventChanges', () => {
1515 }
1616 } )
1717
18- it ( 'does not throw if props not found' , ( ) => {
19- preventChanges ( [ 'name' , 'address' ] , { error : true } ) ( hookBefore )
20- preventChanges ( [ 'name.x' , 'x.y.z' ] , { error : true } ) ( hookBefore )
18+ it ( 'does not throw if props not found' , async ( ) => {
19+ await preventChanges ( [ 'name' , 'address' ] , { error : true } ) ( hookBefore )
20+ await preventChanges ( [ 'name.x' , 'x.y.z' ] , { error : true } ) ( hookBefore )
2121 } )
2222
23- it ( 'throw if props found' , ( ) => {
24- assert . throw ( ( ) => preventChanges ( [ 'name' , 'first' ] , { error : true } ) ( hookBefore ) )
25- assert . throw ( ( ) => preventChanges ( [ 'name' , 'a' ] , { error : true } ) ( hookBefore ) )
26- assert . throw ( ( ) => preventChanges ( [ 'name' , 'a.b' ] , { error : true } ) ( hookBefore ) )
27- assert . throw ( ( ) => preventChanges ( [ 'name' , 'a.c' ] , { error : true } ) ( hookBefore ) )
28- assert . throw ( ( ) => preventChanges ( [ 'name' , 'a.c.d.e' ] , { error : true } ) ( hookBefore ) )
23+ it ( 'throw if props found' , async ( ) => {
24+ await expect ( ( ) =>
25+ preventChanges ( [ 'name' , 'first' ] , { error : true } ) ( hookBefore ) ,
26+ ) . rejects . toThrow ( )
27+ await expect ( ( ) =>
28+ preventChanges ( [ 'name' , 'a' ] , { error : true } ) ( hookBefore ) ,
29+ ) . rejects . toThrow ( )
30+ await expect ( ( ) =>
31+ preventChanges ( [ 'name' , 'a.b' ] , { error : true } ) ( hookBefore ) ,
32+ ) . rejects . toThrow ( )
33+ await expect ( ( ) =>
34+ preventChanges ( [ 'name' , 'a.c' ] , { error : true } ) ( hookBefore ) ,
35+ ) . rejects . toThrow ( )
36+ await expect ( ( ) =>
37+ preventChanges ( [ 'name' , 'a.c.d.e' ] , { error : true } ) ( hookBefore ) ,
38+ ) . rejects . toThrow ( )
2939 } )
3040 } )
3141
@@ -39,38 +49,44 @@ describe('preventChanges', () => {
3949 }
4050 } )
4151
42- it ( 'does not delete if props not found' , ( ) => {
43- let context : any = preventChanges ( [ 'name' , 'address' ] , { error : false } ) ( clone ( hookBefore ) )
52+ it ( 'does not delete if props not found' , async ( ) => {
53+ let context : any = await preventChanges ( [ 'name' , 'address' ] , { error : false } ) (
54+ clone ( hookBefore ) ,
55+ )
4456 assert . deepEqual ( context , hookBefore )
4557
46- context = preventChanges ( [ 'name.x' , 'x.y.z' ] , { error : false } ) ( clone ( hookBefore ) )
58+ context = await preventChanges ( [ 'name.x' , 'x.y.z' ] , { error : false } ) ( clone ( hookBefore ) )
4759 assert . deepEqual ( context , hookBefore )
4860 } )
4961
50- it ( 'deletes if props found' , ( ) => {
51- let context : any = preventChanges ( [ 'name' , 'first' ] , { error : false } ) ( clone ( hookBefore ) )
62+ it ( 'deletes if props found' , async ( ) => {
63+ let context : any = await preventChanges ( [ 'name' , 'first' ] , { error : false } ) (
64+ clone ( hookBefore ) ,
65+ )
5266 assert . deepEqual ( context . data , { last : 'Doe' , a : { b : 'john' , c : { d : { e : 1 } } } } , '1' )
5367
54- context = preventChanges ( [ 'name' , 'a' ] , { error : false } ) ( clone ( hookBefore ) )
68+ context = await preventChanges ( [ 'name' , 'a' ] , { error : false } ) ( clone ( hookBefore ) )
5569 assert . deepEqual ( context . data , { first : 'John' , last : 'Doe' } , '2' )
5670
57- context = preventChanges ( [ 'name' , 'a.b' ] , { error : false } ) ( clone ( hookBefore ) )
71+ context = await preventChanges ( [ 'name' , 'a.b' ] , { error : false } ) ( clone ( hookBefore ) )
5872 assert . deepEqual ( context . data , { first : 'John' , last : 'Doe' , a : { c : { d : { e : 1 } } } } , '3' )
5973
60- context = preventChanges ( [ 'name' , 'a.c' ] , { error : false } ) ( clone ( hookBefore ) )
74+ context = await preventChanges ( [ 'name' , 'a.c' ] , { error : false } ) ( clone ( hookBefore ) )
6175 assert . deepEqual ( context . data , { first : 'John' , last : 'Doe' , a : { b : 'john' } } , '4' )
6276
63- context = preventChanges ( [ 'name' , 'a.c.d.e' ] , { error : false } ) ( clone ( hookBefore ) )
77+ context = await preventChanges ( [ 'name' , 'a.c.d.e' ] , { error : false } ) ( clone ( hookBefore ) )
6478 assert . deepEqual (
6579 context . data ,
6680 { first : 'John' , last : 'Doe' , a : { b : 'john' , c : { d : { } } } } ,
6781 '5' ,
6882 )
6983
70- context = preventChanges ( [ 'first' , 'last' ] , { error : false } ) ( clone ( hookBefore ) )
84+ context = await preventChanges ( [ 'first' , 'last' ] , { error : false } ) ( clone ( hookBefore ) )
7185 assert . deepEqual ( context . data , { a : { b : 'john' , c : { d : { e : 1 } } } } )
7286
73- context = preventChanges ( [ 'first' , 'a.b' , 'a.c.d.e' ] , { error : false } ) ( clone ( hookBefore ) )
87+ context = await preventChanges ( [ 'first' , 'a.b' , 'a.c.d.e' ] , { error : false } ) (
88+ clone ( hookBefore ) ,
89+ )
7490 assert . deepEqual ( context . data , { last : 'Doe' , a : { c : { d : { } } } } )
7591 } )
7692 } )
0 commit comments