| 1 |
var test = require('tape') |
| 2 |
var isFunction = require('./') |
| 3 |
var parse = require('acorn').parse |
| 4 |
|
| 5 |
test('throws if not a node', function (t) { |
| 6 |
t.plan(2) |
| 7 |
t.throws(function () { isFunction(null) }) |
| 8 |
t.throws(function () { isFunction({ whatever: 'xyz' }) }) |
| 9 |
}) |
| 10 |
|
| 11 |
test('FunctionDeclaration', function (t) { |
| 12 |
t.plan(1) |
| 13 |
t.ok(isFunction(parse('function a () {}').body[0])) |
| 14 |
}) |
| 15 |
|
| 16 |
test('ArrowFunction', function (t) { |
| 17 |
t.plan(1) |
| 18 |
t.ok(isFunction(parse('(() => {})').body[0].expression)) |
| 19 |
}) |
| 20 |
|
| 21 |
test('FunctionExpression', function (t) { |
| 22 |
t.plan(2) |
| 23 |
t.ok(isFunction(parse('(function () {})').body[0].expression)) |
| 24 |
t.ok(isFunction(parse('(function a () {})').body[0].expression)) |
| 25 |
}) |
| 26 |
|
| 27 |
test('anything else', function (t) { |
| 28 |
t.plan(3) |
| 29 |
t.notOk(isFunction(parse('10').body[0])) |
| 30 |
t.notOk(isFunction(parse('class A {}').body[0])) |
| 31 |
t.notOk(isFunction(parse('var x = () => {}').body[0])) |
| 32 |
}) |