@@ -259,7 +259,7 @@ describe('$extendsSelf directive', () => {
259
259
await expect ( source . read ( [ extendsSelfDirective ( ) ] ) ) . rejects . toThrow ( ) ;
260
260
} ) ;
261
261
262
- it ( 'fails when $extendsSelf selector is not a string ' , async ( ) => {
262
+ it ( 'fails when $extendsSelf selector is invalid object ' , async ( ) => {
263
263
const source = new LiteralSource ( {
264
264
foo : {
265
265
$extendsSelf : { } ,
@@ -269,6 +269,60 @@ describe('$extendsSelf directive', () => {
269
269
await expect ( source . read ( [ extendsSelfDirective ( ) ] ) ) . rejects . toThrow ( ) ;
270
270
} ) ;
271
271
272
+ it ( 'resolves with select option' , async ( ) => {
273
+ const source = new LiteralSource ( {
274
+ foo : {
275
+ $extendsSelf : {
276
+ select : 'bar' ,
277
+ } ,
278
+ } ,
279
+ bar : 42 ,
280
+ } ) ;
281
+
282
+ expect ( await source . readToJSON ( [ extendsSelfDirective ( ) ] ) ) . toEqual ( { foo : 42 , bar : 42 } ) ;
283
+ } ) ;
284
+
285
+ it ( 'resolves with select and env option' , async ( ) => {
286
+ const source = new LiteralSource ( {
287
+ foo : {
288
+ $extendsSelf : {
289
+ select : 'bar' ,
290
+ env : 'qa' ,
291
+ } ,
292
+ } ,
293
+ bar : {
294
+ $substitute : '$APP_CONFIG_ENV' ,
295
+ } ,
296
+ } ) ;
297
+
298
+ expect ( await source . readToJSON ( [ extendsSelfDirective ( ) , substituteDirective ( ) ] ) ) . toEqual ( {
299
+ foo : 'qa' ,
300
+ bar : 'test' ,
301
+ } ) ;
302
+ } ) ;
303
+
304
+ it ( 'resolves with select and env option' , async ( ) => {
305
+ const source = new LiteralSource ( {
306
+ foo : {
307
+ $extendsSelf : {
308
+ select : 'bar' ,
309
+ env : 'qa' ,
310
+ } ,
311
+ } ,
312
+ bar : {
313
+ $env : {
314
+ default : 42 ,
315
+ qa : 88 ,
316
+ } ,
317
+ } ,
318
+ } ) ;
319
+
320
+ expect ( await source . readToJSON ( [ extendsSelfDirective ( ) , envDirective ( ) ] ) ) . toEqual ( {
321
+ foo : 88 ,
322
+ bar : 42 ,
323
+ } ) ;
324
+ } ) ;
325
+
272
326
it ( 'resolves a simple $extendsSelf selector' , async ( ) => {
273
327
const source = new LiteralSource ( {
274
328
foo : {
0 commit comments