@@ -417,7 +417,8 @@ describe('Test getQueryTypeComplexity function', () => {
417417 describe ( 'with inline fragments' , ( ) => {
418418 describe ( 'on union types' , ( ) => {
419419 let unionTypeWeights : TypeWeightObject ;
420- beforeAll ( ( ) => {
420+ let mockHumanCharacterFriendsFunction : jest . Mock < number , [ ] > ;
421+ beforeEach ( ( ) => {
421422 // type Query {
422423 // hero(episode: Episode): Character
423424 // }
@@ -435,6 +436,7 @@ describe('Test getQueryTypeComplexity function', () => {
435436 // primaryFunction: String
436437 // friends(first: Int): [Character]
437438 // }
439+ mockHumanCharacterFriendsFunction = jest . fn ( ) ;
438440 unionTypeWeights = {
439441 query : {
440442 weight : 1 ,
@@ -446,7 +448,15 @@ describe('Test getQueryTypeComplexity function', () => {
446448 } ,
447449 character : {
448450 weight : 1 ,
449- fields : { } ,
451+ fields : {
452+ name : {
453+ weight : 0 ,
454+ } ,
455+ friends : {
456+ resolveTo : 'character' ,
457+ weight : mockCharacterFriendsFunction ,
458+ } ,
459+ } ,
450460 } ,
451461 human : {
452462 weight : 1 ,
@@ -455,7 +465,7 @@ describe('Test getQueryTypeComplexity function', () => {
455465 homePlanet : { weight : 0 } ,
456466 friends : {
457467 resolveTo : 'character' ,
458- weight : mockCharacterFriendsFunction ,
468+ weight : mockHumanCharacterFriendsFunction ,
459469 } ,
460470 humanFriends : {
461471 resolveTo : 'human' ,
@@ -515,7 +525,7 @@ describe('Test getQueryTypeComplexity function', () => {
515525 }
516526 }` ;
517527 // Query 1 + 1 hero + max(Droid 2, Human 3) = 5
518- mockCharacterFriendsFunction . mockReturnValueOnce ( 3 ) ;
528+ mockHumanCharacterFriendsFunction . mockReturnValueOnce ( 3 ) ;
519529 mockDroidFriendsFunction . mockReturnValueOnce ( 1 ) ;
520530 expect ( getQueryTypeComplexity ( parse ( query ) , variables , unionTypeWeights ) ) . toBe (
521531 5
0 commit comments