@@ -176,7 +176,7 @@ module.exports = function(file, api, options) {
176176 ) ;
177177
178178 if ( options ) {
179- let customMethodBeforeEachBody ;
179+ let customMethodBeforeEachBody , customMethodBeforeEachExpression ;
180180
181181 options . properties . forEach ( property => {
182182 if ( isLifecycleHook ( property ) ) {
@@ -188,13 +188,13 @@ module.exports = function(file, api, options) {
188188
189189 // preserve any comments that were present
190190 lifecycleStatement . comments = property . comments ;
191+ processExpressionForRenderingTest ( lifecycleStatement ) ;
191192
192193 callback . body . body . push ( lifecycleStatement ) ;
193194 } else if ( isMethod ( property ) ) {
194195 if ( ! customMethodBeforeEachBody ) {
195196 customMethodBeforeEachBody = j . blockStatement ( [ ] ) ;
196-
197- let beforeEachInvocation = j . expressionStatement (
197+ customMethodBeforeEachExpression = j . expressionStatement (
198198 j . callExpression (
199199 j . memberExpression ( j . identifier ( 'hooks' ) , j . identifier ( 'beforeEach' ) ) ,
200200 [
@@ -209,7 +209,7 @@ module.exports = function(file, api, options) {
209209 )
210210 ) ;
211211
212- callback . body . body . push ( beforeEachInvocation ) ;
212+ callback . body . body . push ( customMethodBeforeEachExpression ) ;
213213 }
214214
215215 let methodAssignment = j . expressionStatement (
@@ -226,19 +226,17 @@ module.exports = function(file, api, options) {
226226 customMethodBeforeEachBody . body . push ( methodAssignment ) ;
227227 }
228228 } ) ;
229+
230+ if ( customMethodBeforeEachExpression ) {
231+ processExpressionForRenderingTest ( customMethodBeforeEachExpression ) ;
232+ }
229233 }
230234
231235 return [ moduleInvocation , callback . body . body , setupType , subject , hasCustomSubject ] ;
232236 }
233237
234- function processRenderingTest ( testExpression ) {
235- let isTest = j . match ( testExpression , { expression : { callee : { name : 'test' } } } ) ;
236- if ( ! isTest ) {
237- return ;
238- }
239-
238+ function processExpressionForRenderingTest ( testExpression ) {
240239 // mark the test function as an async function
241- testExpression . expression . arguments [ 1 ] . async = true ;
242240 let testExpressionCollection = j ( testExpression ) ;
243241
244242 // Transform to await render() or await clearRender()
@@ -250,6 +248,7 @@ module.exports = function(file, api, options) {
250248 j . callExpression ( j . identifier ( type ) , expression . node . arguments )
251249 ) ;
252250 expression . replace ( awaitExpression ) ;
251+ p . scope . node . async = true ;
253252 } ) ;
254253 } ) ;
255254
@@ -356,8 +355,9 @@ module.exports = function(file, api, options) {
356355 } else if ( currentModuleCallbackBody ) {
357356 currentModuleCallbackBody . push ( expression ) ;
358357
359- if ( currentTestType === 'setupRenderingTest' ) {
360- processRenderingTest ( expression ) ;
358+ let isTest = j . match ( expression , { expression : { callee : { name : 'test' } } } ) ;
359+ if ( isTest && currentTestType === 'setupRenderingTest' ) {
360+ processExpressionForRenderingTest ( expression ) ;
361361 } else if ( currentTestType === 'setupTest' && ! currentHasCustomSubject ) {
362362 processSubject ( expression , currentSubject ) ;
363363 }
0 commit comments