@@ -41,33 +41,29 @@ module.exports = function({ template, types }) {
4141 return ;
4242 }
4343
44- // get the test case body
45- let body = path . node . expression . arguments [ 1 ] . body ;
44+ const test = path . node . expression . arguments [ 1 ] ;
4645
47- // if it's an expression, e.g: () => (expression)
48- if ( types . isCallExpression ( body ) ) {
49- // convert it into a block statement: () => { return (expression); }
50- body = path . node . expression . arguments [ 1 ] . body = types . blockStatement ( [ types . returnStatement ( body ) ] ) ;
46+ if ( types . isCallExpression ( test . body ) ) {
47+ test . body = types . blockStatement ( [ types . returnStatement ( test . body ) ] ) ;
5148 }
5249
53- // generate the code
54- const { code } = generate ( body ) ;
50+ const { code } = generate ( test . body ) ;
5551 const normalisedCode = removeComments ( code ) ;
5652
5753 const count = ( normalisedCode . match ( / e x p e c t \( / g) || [ ] ) . length ;
5854 const containsExpectAssertions = normalisedCode . includes ( 'expect.assertions(' ) ;
5955 const containsHasAssertions = normalisedCode . includes ( 'expect.hasAssertions()' ) ;
6056
61- const args = body . body ;
57+ const body = test . body . body ;
6258
6359 if ( ! containsHasAssertions ) {
6460 const hasAssertions = template ( 'expect.hasAssertions();' ) ( ) ;
65- args . unshift ( hasAssertions ) ;
61+ body . unshift ( hasAssertions ) ;
6662 }
6763
6864 if ( count > 0 && ! containsExpectAssertions ) {
6965 const assertions = template ( `expect.assertions(${ count } )` ) ( ) ;
70- args . unshift ( assertions ) ;
66+ body . unshift ( assertions ) ;
7167 }
7268 }
7369 }
0 commit comments