-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
66 lines (60 loc) · 2.33 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
54
55
56
57
58
59
60
61
62
63
64
65
66
/*!
* is-es6-generators <https://github.com/tunnckoCore/is-es6-generators>
*
* Copyright (c) 2015 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('assertit')
var g = require('./index')
test('is-es6-generators:', function () {
test('should have few aliases', function (done) {
test.equal(typeof g, 'function')
test.equal(typeof g.fn, 'function')
test.equal(typeof g.gen, 'function')
test.equal(typeof g.gen.fn, 'function')
test.equal(typeof g.generator, 'function')
test.equal(typeof g.generator.fn, 'function')
test.equal(typeof g.isGen, 'function')
test.equal(typeof g.isGen.fn, 'function')
test.equal(typeof g.isGenerator, 'function')
test.equal(typeof g.isGeneratorFn, 'function')
test.equal(typeof g.isGenerator.fn, 'function')
test.equal(typeof g.isGeneratorFunction, 'function')
done()
})
test('generators', function () {
test('should return false with non-generators', function () {
test.equal(g.generator(null), false)
test.equal(g.generator(undefined), false)
test.equal(g.generator([1, 2, 3]), false)
test.equal(g.generator({name: 'GeneratorFunction'}), false)
test.equal(g.generator(25), false)
test.equal(g.generator('test'), false)
test.equal(g.generator(function * () {}), false)
})
test('should return true with a generator', function () {
test.equal(g.generator((function * () {})()), true)
test.equal(g.generator((function * () { yield 42 })()), true)
})
})
test('generator functions', function () {
test('should return false with non-generator function', function () {
test.equal(g.gen.fn(null), false)
test.equal(g.gen.fn(undefined), false)
test.equal(g.gen.fn(function () {}), false)
test.equal(g.gen.fn([55, 23, 24]), false)
test.equal(g.gen.fn({name: 'GeneratorFunction'}), false)
test.equal(g.gen.fn(25), false)
test.equal(g.gen.fn('foo bar'), false)
var noConstructorFn = function () {}
noConstructorFn.constructor = undefined
test.equal(g.gen.fn(noConstructorFn), false)
})
test('should return true with a generator functions', function () {
test.equal(g.gen.fn(function * () {}), true)
test.equal(g.gen.fn(function * () { yield 42 }), true)
})
})
})