File "forEach.test.ts"

Full path: /home/fsibplc/public_html/sommilito-bank2/splide-4.1.3/src/js/utils/array/forEach/forEach.test.ts
File size: 743 B (743 B bytes)
MIME-type: text/x-java
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

import { forEach } from './forEach';


describe( 'forEach', () => {
  test( 'can iterate over an array.', () => {
    const array = [ 1, 2, 3 ];
    const callback = jest.fn();

    forEach( array, ( value, index, current ) => {
      expect( value ).toBe( array[ index ] );
      expect( current ).toBe( array );

      callback();
    } );

    expect( callback ).toHaveBeenCalledTimes( array.length );
  } );

  test( 'can push the provided value to a new array and iterate over it.', () => {
    const callback = jest.fn();

    forEach( 1, ( value, index, current ) => {
      expect( value ).toBe( 1 );
      expect( current ).toEqual( [ 1 ] );

      callback();
    } );

    expect( callback ).toHaveBeenCalledTimes( 1 );
  } );
} );