@@ -41,33 +41,29 @@ module.exports = function({ template, types }) {
41
41
return ;
42
42
}
43
43
44
- // get the test case body
45
- let body = path . node . expression . arguments [ 1 ] . body ;
44
+ const test = path . node . expression . arguments [ 1 ] ;
46
45
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 ) ] ) ;
51
48
}
52
49
53
- // generate the code
54
- const { code } = generate ( body ) ;
50
+ const { code } = generate ( test . body ) ;
55
51
const normalisedCode = removeComments ( code ) ;
56
52
57
53
const count = ( normalisedCode . match ( / e x p e c t \( / g) || [ ] ) . length ;
58
54
const containsExpectAssertions = normalisedCode . includes ( 'expect.assertions(' ) ;
59
55
const containsHasAssertions = normalisedCode . includes ( 'expect.hasAssertions()' ) ;
60
56
61
- const args = body . body ;
57
+ const body = test . body . body ;
62
58
63
59
if ( ! containsHasAssertions ) {
64
60
const hasAssertions = template ( 'expect.hasAssertions();' ) ( ) ;
65
- args . unshift ( hasAssertions ) ;
61
+ body . unshift ( hasAssertions ) ;
66
62
}
67
63
68
64
if ( count > 0 && ! containsExpectAssertions ) {
69
65
const assertions = template ( `expect.assertions(${ count } )` ) ( ) ;
70
- args . unshift ( assertions ) ;
66
+ body . unshift ( assertions ) ;
71
67
}
72
68
}
73
69
}
0 commit comments