333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
/* global describe, it */
 
var assert = require('assert')
var isGenerator = require('./')
 
describe('is-generator', function () {
  describe('generators', function () {
    it('should return false with non-generators', function () {
      assert(!isGenerator(null))
      assert(!isGenerator(25))
      assert(!isGenerator('test'))
      assert(!isGenerator(/* istanbul ignore next */ function () {}))
      assert(!isGenerator(/* istanbul ignore next */ function * () {}))
    })
 
    it('should return true with a generator', function () {
      assert(isGenerator((/* istanbul ignore next */ function * () {})()))
    })
  })
 
  describe('generator functions', function () {
    it('should return false with non-generator function', function () {
      assert(!isGenerator.fn(null))
      assert(!isGenerator.fn(25))
      assert(!isGenerator.fn('test'))
      assert(!isGenerator.fn(/* istanbul ignore next */ function () {}))
 
      var noConstructorFn = /* istanbul ignore next */ function () {}
      noConstructorFn.constructor = undefined
 
      assert(!isGenerator.fn(noConstructorFn))
    })
 
    it('should return true with a generator function', function () {
      assert(isGenerator.fn(/* istanbul ignore next */ function * () { yield 'something' }))
    })
  })
})