11import { describe , expect , it } from 'vitest'
22import { fillUnserializableFlytrapValues } from '../src/core/util'
3- import { FLYTRAP_UNSERIALIZABLE_VALUE } from '../src/core/constants'
3+ import { FLYTRAP_REPLACE_VALUES , FLYTRAP_UNSERIALIZABLE_VALUE } from '../src/core/constants'
44
55describe ( 'Replay args' , ( ) => {
66 const mockReplaceValue = {
77 hello : 'world'
88 }
99
1010 it ( 'fills strings' , ( ) => {
11- expect (
12- fillUnserializableFlytrapValues ( FLYTRAP_UNSERIALIZABLE_VALUE , 'hello world' )
13- ) . toStrictEqual ( 'hello world' )
11+ FLYTRAP_REPLACE_VALUES . forEach ( ( replaceValue ) => {
12+ expect ( fillUnserializableFlytrapValues ( replaceValue , 'hello world' ) ) . toStrictEqual (
13+ 'hello world'
14+ )
15+ } )
1416 } )
1517
1618 it ( 'fills numbers' , ( ) => {
17- expect ( fillUnserializableFlytrapValues ( FLYTRAP_UNSERIALIZABLE_VALUE , 1 ) ) . toStrictEqual ( 1 )
19+ FLYTRAP_REPLACE_VALUES . forEach ( ( replaceValue ) => {
20+ expect ( fillUnserializableFlytrapValues ( replaceValue , 1 ) ) . toStrictEqual ( 1 )
21+ } )
1822 } )
1923
2024 it ( 'fills arrays' , ( ) => {
21- expect (
22- fillUnserializableFlytrapValues ( [ FLYTRAP_UNSERIALIZABLE_VALUE ] , [ mockReplaceValue ] )
23- ) . toStrictEqual ( [ mockReplaceValue ] )
24- expect (
25- fillUnserializableFlytrapValues (
26- [ FLYTRAP_UNSERIALIZABLE_VALUE , FLYTRAP_UNSERIALIZABLE_VALUE ] ,
27- [ mockReplaceValue , mockReplaceValue ]
28- )
29- ) . toStrictEqual ( [ mockReplaceValue , mockReplaceValue ] )
25+ FLYTRAP_REPLACE_VALUES . forEach ( ( replaceValue ) => {
26+ expect ( fillUnserializableFlytrapValues ( [ replaceValue ] , [ mockReplaceValue ] ) ) . toStrictEqual ( [
27+ mockReplaceValue
28+ ] )
29+ expect (
30+ fillUnserializableFlytrapValues (
31+ [ replaceValue , replaceValue ] ,
32+ [ mockReplaceValue , mockReplaceValue ]
33+ )
34+ ) . toStrictEqual ( [ mockReplaceValue , mockReplaceValue ] )
35+ } )
3036 } )
3137
3238 it ( 'works with null and undefined' , ( ) => {
@@ -39,47 +45,45 @@ describe('Replay args', () => {
3945 } )
4046
4147 it ( 'throws when matching keys not same shape' , ( ) => {
42- expect ( ( ) =>
43- fillUnserializableFlytrapValues (
44- { hello : [ FLYTRAP_UNSERIALIZABLE_VALUE ] } ,
45- { hello : mockReplaceValue }
46- )
47- ) . toThrow ( )
48+ FLYTRAP_REPLACE_VALUES . forEach ( ( replaceValue ) => {
49+ expect ( ( ) =>
50+ fillUnserializableFlytrapValues ( { hello : [ replaceValue ] } , { hello : mockReplaceValue } )
51+ ) . toThrow ( )
4852
49- expect ( ( ) =>
50- fillUnserializableFlytrapValues (
51- { hello : [ FLYTRAP_UNSERIALIZABLE_VALUE ] , world : [ ] } ,
52- { hello : [ mockReplaceValue ] }
53- )
54- ) . not . toThrow ( )
53+ expect ( ( ) =>
54+ fillUnserializableFlytrapValues (
55+ { hello : [ replaceValue ] , world : [ ] } ,
56+ { hello : [ mockReplaceValue ] }
57+ )
58+ ) . not . toThrow ( )
5559
56- expect ( ( ) =>
57- fillUnserializableFlytrapValues (
58- { hello : FLYTRAP_UNSERIALIZABLE_VALUE , world : [ ] } ,
59- { mockReplaceValue }
60- )
61- ) . toThrow ( )
60+ expect ( ( ) =>
61+ fillUnserializableFlytrapValues ( { hello : replaceValue , world : [ ] } , { mockReplaceValue } )
62+ ) . toThrow ( )
63+ } )
6264 } )
6365
6466 it ( 'fills objects' , ( ) => {
65- const lackingObj = { hello : FLYTRAP_UNSERIALIZABLE_VALUE , otherKey : '' }
66- expect (
67- fillUnserializableFlytrapValues ( lackingObj , { hello : mockReplaceValue , otherKey : '' } )
68- ) . toStrictEqual ( {
69- hello : mockReplaceValue ,
70- otherKey : ''
71- } )
67+ FLYTRAP_REPLACE_VALUES . forEach ( ( replaceValue ) => {
68+ const lackingObj = { hello : replaceValue , otherKey : '' }
69+ expect (
70+ fillUnserializableFlytrapValues ( lackingObj , { hello : mockReplaceValue , otherKey : '' } )
71+ ) . toStrictEqual ( {
72+ hello : mockReplaceValue ,
73+ otherKey : ''
74+ } )
7275
73- const lackingObjDeep = {
74- hello : { world : { deep : FLYTRAP_UNSERIALIZABLE_VALUE } } ,
75- otherKey : ''
76- }
77- const fillObjDeep = { hello : { world : { deep : { hello : 'world' } } } , otherKey : '' }
78- const fillObjDeepWrong = { deep : { hello : 'world' } }
79- expect ( fillUnserializableFlytrapValues ( lackingObjDeep , fillObjDeep ) ) . toStrictEqual ( {
80- ...fillObjDeep ,
81- otherKey : ''
76+ const lackingObjDeep = {
77+ hello : { world : { deep : replaceValue } } ,
78+ otherKey : ''
79+ }
80+ const fillObjDeep = { hello : { world : { deep : { hello : 'world' } } } , otherKey : '' }
81+ const fillObjDeepWrong = { deep : { hello : 'world' } }
82+ expect ( fillUnserializableFlytrapValues ( lackingObjDeep , fillObjDeep ) ) . toStrictEqual ( {
83+ ...fillObjDeep ,
84+ otherKey : ''
85+ } )
86+ expect ( ( ) => fillUnserializableFlytrapValues ( lackingObjDeep , fillObjDeepWrong ) ) . toThrow ( )
8287 } )
83- expect ( ( ) => fillUnserializableFlytrapValues ( lackingObjDeep , fillObjDeepWrong ) ) . toThrow ( )
8488 } )
8589} )
0 commit comments