isIterable.js 1.1 KB

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