jeudi 22 octobre 2020

Why is Jest testing my scripts.js file instead of scripts.test.js?

I am trying to write tests for my javascript game using Jest for the first time. When I run the tests, jest is saying:

FAIL ./scripts.test.js ● Test suite failed to run

TypeError: Cannot set property 'onclick' of undefined

  87 |
  88 | //  close button for modal
> 89 | span.onclick = function() {
     | ^

  90 |     modal.style.display = "none";
  91 |   }
  92 |

I don't understand why it going to the span.onClick function, when I am only exporting addTwo function for testing. I wrote a simple test in scripts.test.js file, which is what I want jest to use for the test?

Any help would be greatly appreciated. THANKS!

package.json: { "name": "cardGame", "version": "1.0.0", "description": "", "main": "scripts.js", "scripts": { "test": "jest" },

Aucun commentaire:

Enregistrer un commentaire