vendredi 31 mai 2019

Jest Testing import a basic function and run test

I want to implement jest to a small project written with Javascript ES6. Below, you can see how I tried to implement one function. Where do you think I do wrong?

I have function that adds the arguments

function findTotal(a, b) {
  return a + b;
}
}

and I export it

export default { findTotal };

Then I import it in my test file

import { findTotal } from "../src/assessment";

Then the test itself

import { findTotal } from "../src/assessment";


describe("The Total", () => {

  it("should find total", () => {

    expect(findTotal(1, 2)).toBe(3);
  });

});

Result


     ● The total › should find total

    TypeError: (0 , _assessment.findTotal) is not a function

      at Object.<anonymous> (test/assessment.test.js:5:38)
          at new Promise (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

Aucun commentaire:

Enregistrer un commentaire