Skip to content

Commit

Permalink
fix(valid-describe): support TemplateLiteral first argument (#77)
Browse files Browse the repository at this point in the history
Resolves #75
  • Loading branch information
macklinu authored and SimenB committed Feb 13, 2018
1 parent ad377d8 commit 47eb6c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions rules/__tests__/valid-describe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ruleTester.run('valid-describe', rules['valid-describe'], {
valid: [
'describe("foo", function() {})',
'describe("foo", () => {})',
'describe(`foo`, () => {})',
'xdescribe("foo", () => {})',
'fdescribe("foo", () => {})',
'describe.only("foo", () => {})',
Expand Down
10 changes: 7 additions & 3 deletions rules/valid-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const isFunction = require('./util').isFunction;

const isAsync = node => node.async;

const isString = node =>
(node.type === 'Literal' && typeof node.value === 'string') ||
node.type === 'TemplateLiteral';

const hasParams = node => node.params.length > 0;

const paramsLocation = params => {
Expand Down Expand Up @@ -35,19 +39,19 @@ module.exports = {
if (isDescribe(node)) {
const name = node.arguments[0];
const callbackFunction = node.arguments[1];
if (name.type !== 'Literal') {
if (!isString(name)) {
context.report({
message: 'First argument must be name',
loc: paramsLocation(node.arguments),
});
}
if (callbackFunction === undefined) {
context.report({
return context.report({
message: 'Describe requires name and callback arguments',
loc: paramsLocation(node.arguments),
});
}
if (callbackFunction && isFunction(callbackFunction)) {
if (isFunction(callbackFunction)) {
if (isAsync(callbackFunction)) {
context.report({
message: 'No async describe callback',
Expand Down

0 comments on commit 47eb6c2

Please # to comment.