@@ -179,6 +179,8 @@ module.exports = function(file, api, options) {
179179 let customMethodBeforeEachBody , customMethodBeforeEachExpression ;
180180
181181 options . properties . forEach ( property => {
182+ updateGetOwnerThisUsage ( property . value ) ;
183+
182184 if ( isLifecycleHook ( property ) ) {
183185 let lifecycleStatement = j . expressionStatement (
184186 j . callExpression ( j . memberExpression ( j . identifier ( 'hooks' ) , property . key ) , [
@@ -357,10 +359,13 @@ module.exports = function(file, api, options) {
357359 currentModuleCallbackBody . push ( expression ) ;
358360
359361 let isTest = j . match ( expression , { expression : { callee : { name : 'test' } } } ) ;
360- if ( isTest && currentTestType === 'setupRenderingTest' ) {
361- processExpressionForRenderingTest ( expression ) ;
362- } else if ( currentTestType === 'setupTest' && ! currentHasCustomSubject ) {
363- processSubject ( expression , currentSubject ) ;
362+ if ( isTest ) {
363+ updateGetOwnerThisUsage ( expression . expression . arguments [ 1 ] ) ;
364+ if ( currentTestType === 'setupRenderingTest' ) {
365+ processExpressionForRenderingTest ( expression ) ;
366+ } else if ( currentTestType === 'setupTest' && ! currentHasCustomSubject ) {
367+ processSubject ( expression , currentSubject ) ;
368+ }
364369 }
365370 } else {
366371 bodyReplacement . push ( expression ) ;
@@ -452,20 +457,25 @@ module.exports = function(file, api, options) {
452457 } ) ;
453458 }
454459
455- function updateGetOwnerThisUsage ( ) {
460+ function updateGetOwnerThisUsage ( expression ) {
461+ let expressionCollection = j ( expression ) ;
456462 let thisDotOwner = j . memberExpression ( j . thisExpression ( ) , j . identifier ( 'owner' ) ) ;
457463
458- root
464+ function replacement ( path ) {
465+ if ( path . scope . node === expression ) {
466+ path . replace ( thisDotOwner ) ;
467+ }
468+ }
469+
470+ expressionCollection
459471 . find ( j . CallExpression , {
460472 callee : {
461473 name : 'getOwner' ,
462474 } ,
463475 } )
464- . forEach ( path => {
465- path . replace ( thisDotOwner ) ;
466- } ) ;
476+ . forEach ( replacement ) ;
467477
468- root
478+ expressionCollection
469479 . find ( j . CallExpression , {
470480 callee : {
471481 type : 'MemberExpression' ,
@@ -477,9 +487,7 @@ module.exports = function(file, api, options) {
477487 } ,
478488 } ,
479489 } )
480- . forEach ( path => {
481- path . replace ( thisDotOwner ) ;
482- } ) ;
490+ . forEach ( replacement ) ;
483491 }
484492
485493 const printOptions = options . printOptions || { quote : 'single' } ;
@@ -496,7 +504,6 @@ module.exports = function(file, api, options) {
496504 updateLookupCalls ( ) ;
497505 updateRegisterCalls ( ) ;
498506 updateInjectCalls ( ) ;
499- updateGetOwnerThisUsage ( ) ;
500507
501508 return root . toSource ( printOptions ) ;
502509} ;
0 commit comments