This repository was archived by the owner on Jul 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,31 @@ describe('resolver', () => {
160160 expect ( resolved . result . hello ) . toBe ( 'world' ) ;
161161 } ) ;
162162
163+ test ( 'should only resolve valid $refs' , async ( ) => {
164+ const source = {
165+ hello : {
166+ $ref : {
167+ foo : 'bear' ,
168+ } ,
169+ } ,
170+ word : 'world' ,
171+ } ;
172+
173+ const resolver = new Resolver ( ) ;
174+ let resolved = await resolver . resolve ( source ) ;
175+ expect ( resolved . result ) . toEqual ( source ) ;
176+
177+ // @ts -ignore
178+ source . hello . $ref = true ;
179+ resolved = await resolver . resolve ( source ) ;
180+ expect ( resolved . result ) . toEqual ( source ) ;
181+
182+ // @ts -ignore
183+ source . hello . $ref = 1 ;
184+ resolved = await resolver . resolve ( source ) ;
185+ expect ( resolved . result ) . toEqual ( source ) ;
186+ } ) ;
187+
163188 test ( 'should support not resolving pointers' , async ( ) => {
164189 const source = {
165190 hello : {
Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ const memoize = require('fast-memoize');
1414let resolveRunnerCount = 0 ;
1515
1616export const defaultGetRef = ( key : string , val : any ) => {
17- if ( val && typeof val === 'object' && val . $ref ) {
18- return val . $ref ;
19- }
20-
17+ if ( val && typeof val === 'object' && typeof val . $ref === 'string' ) return val . $ref ;
2118 return ;
2219} ;
2320
You can’t perform that action at this time.
0 commit comments