-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
53 lines (44 loc) · 1.43 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*!
* function-arguments <https://github.com/tunnckoCore/function-arguments>
*
* Copyright (c) 2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('mukla')
var fnArgs = require('./index')
test('should throw if not a function is passed', function (done) {
function fixture () {
fnArgs(123)
}
test.throws(fixture, TypeError)
test.throws(fixture, /expect a function/)
done()
})
test('should return empty array if not arguments', function (done) {
test.deepEqual(fnArgs(function () {}), [])
done()
})
test('should work when using comments', function (done) {
test.deepEqual(fnArgs(function /* something */ (
// go,
go,
/* wrong, */
here
// (when, using, comments) {}
) {}), ['go', 'here'])
done()
})
test('should get array with arguments names from regular function', function (done) {
test.deepEqual(fnArgs(function (a, b, c) {}), ['a', 'b', 'c'])
test.deepEqual(fnArgs(function named (a, b, c) {}), ['a', 'b', 'c'])
done()
})
test('should get arguments of an arrow and generator functions', function (done) {
test.deepEqual(fnArgs(a => {}), ['a']) // eslint-disable-line arrow-parens
test.deepEqual(fnArgs((a, b) => {}), ['a', 'b'])
test.deepEqual(fnArgs(function * (a, b, c) {}), ['a', 'b', 'c'])
test.deepEqual(fnArgs(function * named (a, b, c) {}), ['a', 'b', 'c'])
done()
})