vendredi 5 juin 2020

How to test array in Jest

Beginners question. I was trying out Jest. But the following is giving error.

the newArray.js file

const mapNewFn = array => array.map( el => el = el*2 );
mapNewFn(num)

the newArray.test.js

const newArray = require('./newArray');


test('mapNewFn function exists', () =>{
    expect(newArray.mapNewFn).toBeDefined();
});

test('use map to multiply array by 2', () => {
    let numbers = [1, 2, 3, 4, 5]
    expect(newArray.mapNewFn(numbers)).toEqual([2, 4, 6, 8, 10])
});

both tests are failing. Help please!

Aucun commentaire:

Enregistrer un commentaire