8
0

nth.js 854 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import nth from '/ckeditor5/utils/nth.js';
  6. describe( 'utils', () => {
  7. describe( 'nth', () => {
  8. it( 'should return 0th item', () => {
  9. expect( nth( 0, getIterator() ) ).to.equal( 11 );
  10. } );
  11. it( 'should return the last item', () => {
  12. expect( nth( 2, getIterator() ) ).to.equal( 33 );
  13. } );
  14. it( 'should return null if out of range (bottom)', () => {
  15. expect( nth( -1, getIterator() ) ).to.be.null;
  16. } );
  17. it( 'should return null if out of range (top)', () => {
  18. expect( nth( 3, getIterator() ) ).to.be.null;
  19. } );
  20. it( 'should return null if iterator is empty', () => {
  21. expect( nth( 0, [] ) ).to.be.null;
  22. } );
  23. function *getIterator() {
  24. yield 11;
  25. yield 22;
  26. yield 33;
  27. }
  28. } );
  29. } );