test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* global describe, it */
  2. var assert = require('assert')
  3. var isGenerator = require('./')
  4. describe('is-generator', function () {
  5. describe('generators', function () {
  6. it('should return false with non-generators', function () {
  7. assert(!isGenerator(null))
  8. assert(!isGenerator(25))
  9. assert(!isGenerator('test'))
  10. assert(!isGenerator(/* istanbul ignore next */ function () {}))
  11. assert(!isGenerator(/* istanbul ignore next */ function * () {}))
  12. })
  13. it('should return true with a generator', function () {
  14. assert(isGenerator((/* istanbul ignore next */ function * () {})()))
  15. })
  16. })
  17. describe('generator functions', function () {
  18. it('should return false with non-generator function', function () {
  19. assert(!isGenerator.fn(null))
  20. assert(!isGenerator.fn(25))
  21. assert(!isGenerator.fn('test'))
  22. assert(!isGenerator.fn(/* istanbul ignore next */ function () {}))
  23. var noConstructorFn = /* istanbul ignore next */ function () {}
  24. noConstructorFn.constructor = undefined
  25. assert(!isGenerator.fn(noConstructorFn))
  26. })
  27. it('should return true with a generator function', function () {
  28. assert(isGenerator.fn(/* istanbul ignore next */ function * () { yield 'something' }))
  29. })
  30. })
  31. })