first.js 875 B

123456789101112131415161718192021222324252627282930313233
  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 first from '../src/first';
  6. describe( 'utils', () => {
  7. describe( 'first', () => {
  8. it( 'should return first item', () => {
  9. const collection = [ 11, 22 ];
  10. const iterator = collection[ Symbol.iterator ]();
  11. expect( first( iterator ) ).to.equal( 11 );
  12. } );
  13. it( 'should return null if iterator is empty', () => {
  14. const collection = [];
  15. const iterator = collection[ Symbol.iterator ]();
  16. expect( first( iterator ) ).to.be.null;
  17. } );
  18. it( 'should consume the iterating item', () => {
  19. const collection = [ 11, 22 ];
  20. const iterator = collection[ Symbol.iterator ]();
  21. first( iterator );
  22. expect( iterator.next().value ).to.equal( 22 );
  23. } );
  24. } );
  25. } );