@@ -49,6 +49,46 @@ module('@glimmer/validator: trackedMap', function () {
4949 assert . strictEqual ( map . get ( 'foo' ) , 456 ) ;
5050 } ) ;
5151
52+ test ( 'getOrInsert' , ( assert ) => {
53+ const map = trackedMap ( ) ;
54+
55+ if (
56+ 'getOrInsert' in map &&
57+ typeof map . getOrInsert === 'function' &&
58+ 'getOrInsert' in Map . prototype
59+ ) {
60+ let v = map . getOrInsert ( 'foo' , 123 ) ;
61+ assert . strictEqual ( v , 123 ) ;
62+
63+ assert . strictEqual ( map . get ( 'foo' ) , 123 ) ;
64+
65+ // eslint-disable-next-line qunit/no-early-return
66+ return ;
67+ }
68+
69+ assert . ok ( 'This browser has not implemented getOrInsert' ) ;
70+ } ) ;
71+
72+ test ( 'getOrInsertComputed' , ( assert ) => {
73+ const map = trackedMap ( ) ;
74+
75+ if (
76+ 'getOrInsertComputed' in map &&
77+ typeof map . getOrInsertComputed === 'function' &&
78+ 'getOrInsertComputed' in Map . prototype
79+ ) {
80+ let v = map . getOrInsertComputed ( 'foo' , ( key : string ) => `${ key } !` ) ;
81+ assert . strictEqual ( v , 'foo!' ) ;
82+
83+ assert . strictEqual ( map . get ( 'foo' ) , 'foo!' ) ;
84+
85+ // eslint-disable-next-line qunit/no-early-return
86+ return ;
87+ }
88+
89+ assert . ok ( 'This browser has not implemented getOrInsert' ) ;
90+ } ) ;
91+
5292 test ( 'has' , ( assert ) => {
5393 const map = trackedMap ( ) ;
5494
0 commit comments