@@ -35,6 +35,50 @@ function setup(
3535afterEach ( ( ) => vi . useRealTimers ( ) ) ;
3636
3737describe ( "v2 snapshots" , ( ) => {
38+ test ( "owns singular results as well as batch and fetched snapshots" , ( ) => {
39+ const flag = selectedFlag ( { nested : [ 1 ] } ) ;
40+ const { client } = setup ( {
41+ bootstrappedState : {
42+ protocolVersion : 2 ,
43+ flags : { settings : flag } ,
44+ } ,
45+ } ) ;
46+ const singular = client . getFlag ( "settings" ) ! ;
47+ ( singular . value as { nested : number [ ] } ) . nested . push ( 2 ) ;
48+ singular . ruleResults [ 0 ] . matched = false ;
49+ singular . errors . push ( { code : "TEST" , message : "mutated" } ) ;
50+ expect ( client . getFlag ( "settings" ) ) . toEqual ( flag ) ;
51+
52+ const batch = client . getFlags ( ) ;
53+ batch . settings . value = false ;
54+ batch . settings . ruleResults [ 0 ] . matched = false ;
55+ const fetched = client . getFetchedFlags ( ) ;
56+ fetched . settings . value = false ;
57+ fetched . settings . ruleResults [ 0 ] . matched = false ;
58+ expect ( client . getFlags ( ) ) . toEqual ( { settings : flag } ) ;
59+ expect ( client . getFetchedFlags ( ) ) . toEqual ( { settings : flag } ) ;
60+ expect ( client . getFlag ( "settings" ) ) . toEqual ( flag ) ;
61+ } ) ;
62+
63+ test . each ( [ "missing" , "constructor" , "toString" , "__proto__" ] ) (
64+ "returns undefined for the absent key %s" ,
65+ ( key ) => {
66+ const { client } = setup ( ) ;
67+ expect ( client . getFlag ( key ) ) . toBeUndefined ( ) ;
68+ } ,
69+ ) ;
70+
71+ test . each ( [ "constructor" , "toString" , "__proto__" ] ) (
72+ "reads an authored flag with the key %s" ,
73+ ( key ) => {
74+ const flag = selectedFlag ( false ) ;
75+ const { client } = setup ( {
76+ bootstrappedState : { protocolVersion : 2 , flags : { [ key ] : flag } } ,
77+ } ) ;
78+ expect ( client . getFlag ( key ) ) . toEqual ( flag ) ;
79+ } ,
80+ ) ;
81+
3882 test . each ( [
3983 [ "legacy protocol" , { success : true , features : { } } ] ,
4084 [
0 commit comments