isIterable.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import isIterable from '../src/isiterable';
  6. describe( 'utils', () => {
  7. describe( 'isIterable', () => {
  8. it( 'should be true for string', () => {
  9. const string = 'foo';
  10. expect( isIterable( string ) ).to.be.true;
  11. } );
  12. it( 'should be true for arrays', () => {
  13. const array = [ 1, 2, 3 ];
  14. expect( isIterable( array ) ).to.be.true;
  15. } );
  16. it( 'should be true for iterable classes', () => {
  17. class IterableClass {
  18. constructor() {
  19. this.array = [ 1, 2, 3 ];
  20. }
  21. [ Symbol.iterator ]() {
  22. return this.array[ Symbol.iterator ]();
  23. }
  24. }
  25. const instance = new IterableClass();
  26. expect( isIterable( instance ) ).to.be.true;
  27. } );
  28. it( 'should be false for not iterable objects', () => {
  29. const notIterable = { foo: 'bar' };
  30. expect( isIterable( notIterable ) ).to.be.false;
  31. } );
  32. it( 'should be false for undefined', () => {
  33. expect( isIterable() ).to.be.false;
  34. } );
  35. } );
  36. } );