Skip to content

Commit 47eb6c2

Browse files
macklinuSimenB
authored andcommittedFeb 13, 2018
fix(valid-describe): support TemplateLiteral first argument (#77)
Resolves #75
1 parent ad377d8 commit 47eb6c2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
 

Diff for: ‎rules/__tests__/valid-describe.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ruleTester.run('valid-describe', rules['valid-describe'], {
1313
valid: [
1414
'describe("foo", function() {})',
1515
'describe("foo", () => {})',
16+
'describe(`foo`, () => {})',
1617
'xdescribe("foo", () => {})',
1718
'fdescribe("foo", () => {})',
1819
'describe.only("foo", () => {})',

Diff for: ‎rules/valid-describe.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const isFunction = require('./util').isFunction;
55

66
const isAsync = node => node.async;
77

8+
const isString = node =>
9+
(node.type === 'Literal' && typeof node.value === 'string') ||
10+
node.type === 'TemplateLiteral';
11+
812
const hasParams = node => node.params.length > 0;
913

1014
const paramsLocation = params => {
@@ -35,19 +39,19 @@ module.exports = {
3539
if (isDescribe(node)) {
3640
const name = node.arguments[0];
3741
const callbackFunction = node.arguments[1];
38-
if (name.type !== 'Literal') {
42+
if (!isString(name)) {
3943
context.report({
4044
message: 'First argument must be name',
4145
loc: paramsLocation(node.arguments),
4246
});
4347
}
4448
if (callbackFunction === undefined) {
45-
context.report({
49+
return context.report({
4650
message: 'Describe requires name and callback arguments',
4751
loc: paramsLocation(node.arguments),
4852
});
4953
}
50-
if (callbackFunction && isFunction(callbackFunction)) {
54+
if (isFunction(callbackFunction)) {
5155
if (isAsync(callbackFunction)) {
5256
context.report({
5357
message: 'No async describe callback',

0 commit comments

Comments
 (0)
Please sign in to comment.