vendredi 23 octobre 2020

How can I test my calculator using npm test?

I have a simple calculator web project: https://github.com/DANIILNEDOSTUP/js-calculator

I want to do simple tests (addition and subtraction for example) using npm + jest. I created package.json and wrote these lines:

{
  "scripts": {
    "test": "jest"
  }
}

then created script.test.js file and wrote lines:

const add = require('./script');

test('adds 1 + 2 to equal 3', () => {
  expect(add(1, 2)).toBe(3);
});

then I call a npm test command from terminal (I use Ubuntu 20.04)

Then I see a mistake:

TypeError: Cannot read property 'addEventListener' of null

and complains about 131 lines of code

clearKey.addEventLisener('click', clearEquation);

Is it realistic to do a test?
I want to make CI / CD for this application, I don't really understand JavaScript.

Aucun commentaire:

Enregistrer un commentaire