nth.js 869 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 nth from '/ckeditor5/utils/nth.js';
  7. describe( 'utils', () => {
  8. describe( 'nth', () => {
  9. it( 'should return 0th item', () => {
  10. expect( nth( 0, getIterator() ) ).to.equal( 11 );
  11. } );
  12. it( 'should return the last item', () => {
  13. expect( nth( 2, getIterator() ) ).to.equal( 33 );
  14. } );
  15. it( 'should return null if out of range (bottom)', () => {
  16. expect( nth( -1, getIterator() ) ).to.be.null;
  17. } );
  18. it( 'should return null if out of range (top)', () => {
  19. expect( nth( 3, getIterator() ) ).to.be.null;
  20. } );
  21. it( 'should return null if iterator is empty', () => {
  22. expect( nth( 0, [] ) ).to.be.null;
  23. } );
  24. function *getIterator() {
  25. yield 11;
  26. yield 22;
  27. yield 33;
  28. }
  29. } );
  30. } );