Skip to content

Commit f620a80

Browse files
authored
Placeholder test (#5)
* Add function body check to testBlock definition * Add SBoudrias to contributors list
1 parent 73ca48d commit f620a80

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
"contributions": [
4040
"bug"
4141
]
42+
},
43+
{
44+
"login": "SBoudrias",
45+
"name": "Simon Boudrias",
46+
"avatar_url": "https://avatars2.githubusercontent.com/u/923865?v=4",
47+
"profile": "http://simonboudrias.com",
48+
"contributions": [
49+
"bug"
50+
]
4251
}
4352
]
4453
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ it('will leave test as override supplied', () => {
211211
## Contributors
212212

213213
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
214-
| [<img src="https://avatars0.githubusercontent.com/u/5610087?v=4" width="100px;"/><br /><sub>Matt Phillips</sub>](http://mattphillips.io)<br />[💻](https://github.com/mattphillips/babel-jest-assertions/commits?author=mattphillips "Code") [📖](https://github.com/mattphillips/babel-jest-assertions/commits?author=mattphillips "Documentation") [🚇](#infra-mattphillips "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/mattphillips/babel-jest-assertions/commits?author=mattphillips "Tests") | [<img src="https://avatars0.githubusercontent.com/u/266594?v=4" width="100px;"/><br /><sub>Ramesh Nair</sub>](https://hiddentao.com/)<br />[💻](https://github.com/mattphillips/babel-jest-assertions/commits?author=hiddentao "Code") [📖](https://github.com/mattphillips/babel-jest-assertions/commits?author=hiddentao "Documentation") [💡](#example-hiddentao "Examples") [⚠️](https://github.com/mattphillips/babel-jest-assertions/commits?author=hiddentao "Tests") | [<img src="https://avatars1.githubusercontent.com/u/7352279?v=4" width="100px;"/><br /><sub>Huy Nguyen</sub>](https://www.huy-nguyen.com/)<br />[🐛](https://github.com/mattphillips/babel-jest-assertions/issues?q=author%3Ahuy-nguyen "Bug reports") |
215-
| :---: | :---: | :---: |
214+
| [<img src="https://avatars0.githubusercontent.com/u/5610087?v=4" width="100px;"/><br /><sub>Matt Phillips</sub>](http://mattphillips.io)<br />[💻](https://github.com/mattphillips/babel-jest-assertions/commits?author=mattphillips "Code") [📖](https://github.com/mattphillips/babel-jest-assertions/commits?author=mattphillips "Documentation") [🚇](#infra-mattphillips "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/mattphillips/babel-jest-assertions/commits?author=mattphillips "Tests") | [<img src="https://avatars0.githubusercontent.com/u/266594?v=4" width="100px;"/><br /><sub>Ramesh Nair</sub>](https://hiddentao.com/)<br />[💻](https://github.com/mattphillips/babel-jest-assertions/commits?author=hiddentao "Code") [📖](https://github.com/mattphillips/babel-jest-assertions/commits?author=hiddentao "Documentation") [💡](#example-hiddentao "Examples") [⚠️](https://github.com/mattphillips/babel-jest-assertions/commits?author=hiddentao "Tests") | [<img src="https://avatars1.githubusercontent.com/u/7352279?v=4" width="100px;"/><br /><sub>Huy Nguyen</sub>](https://www.huy-nguyen.com/)<br />[🐛](https://github.com/mattphillips/babel-jest-assertions/issues?q=author%3Ahuy-nguyen "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/923865?v=4" width="100px;"/><br /><sub>Simon Boudrias</sub>](http://simonboudrias.com)<br />[🐛](https://github.com/mattphillips/babel-jest-assertions/issues?q=author%3ASBoudrias "Bug reports") |
215+
| :---: | :---: | :---: | :---: |
216216
<!-- ALL-CONTRIBUTORS-LIST:END -->
217217

218218
## LICENSE

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ const generate = require('babel-generator').default;
33
const looksLike = require('./utils/looks-like');
44
const { removeComments } = require('./utils');
55

6+
const hasBodyFunction = args =>
7+
looksLike(args[1], {
8+
type: t => t === 'ArrowFunctionExpression' || t === 'FunctionExpression'
9+
});
10+
611
module.exports = function({ template, types }) {
712
return {
813
name: 'babel-assertions',
@@ -14,7 +19,8 @@ module.exports = function({ template, types }) {
1419
callee: {
1520
type: 'Identifier',
1621
name: n => n === 'it' || n === 'test' || n === 'fit' || n === 'ftest'
17-
}
22+
},
23+
arguments: hasBodyFunction
1824
}
1925
}
2026
});
@@ -32,7 +38,8 @@ module.exports = function({ template, types }) {
3238
type: 'Identifier',
3339
name: 'only'
3440
}
35-
}
41+
},
42+
arguments: hasBodyFunction
3643
}
3744
}
3845
});

src/sync.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,65 @@ pluginTester({
99
const add = (a, b) => a + b;
1010
`
1111
},
12+
'Does not modify code given an inline value for function body': {
13+
code: `
14+
describe('.add', () => {
15+
test('handles variables', noop);
16+
test('handles numbers', 1);
17+
test('handles booleans', true);
18+
test('handles objects', {});
19+
test('handles arrays', []);
20+
test('handles maps', new Map());
21+
test('handles sets', new Set());
22+
test('handles symbols', Symbol('x'));
23+
test('handles undefined', undefined);
24+
test('handles strings', 'hello');
25+
test('handles null', null);
26+
});
27+
`
28+
},
29+
'Does not modify code given an empty test placeholder': {
30+
code: `
31+
describe('.add', () => {
32+
test('returns 3 when given 2 and 1');
33+
});
34+
`
35+
},
36+
'Does not modify code given an empty ftest placeholder': {
37+
code: `
38+
describe('.add', () => {
39+
ftest('returns 3 when given 2 and 1');
40+
});
41+
`
42+
},
43+
'Does not modify code given an empty test.only placeholder': {
44+
code: `
45+
describe('.add', () => {
46+
test.only('returns 3 when given 2 and 1');
47+
});
48+
`
49+
},
50+
'Does not modify code given an empty it placeholder': {
51+
code: `
52+
describe('.add', () => {
53+
it('returns 3 when given 2 and 1');
54+
});
55+
`
56+
},
57+
'Does not modify code given an empty fit placeholder': {
58+
code: `
59+
describe('.add', () => {
60+
fit('returns 3 when given 2 and 1');
61+
});
62+
`
63+
},
64+
'Does not modify code given an empty it.only placeholder': {
65+
code: `
66+
describe('.add', () => {
67+
it.only('returns 3 when given 2 and 1');
68+
});
69+
`
70+
},
1271
'Adds number of assertions and has assertions check when given one expect statement': {
1372
snapshot: true,
1473
code: `

0 commit comments

Comments
 (0)