vendredi 23 septembre 2016

New to testing, how would I test this method with Mocha, Chai, Enzyme, and Sinon?

Here's my method

  handleKeyEvent(event) {
    const code = event.keyCode;

    if (UsedKeys.includes(code)) {
      event.preventDefault();

      if (code === KeyCodes.DOWN) {
        this.modifyIndexBy(1);
      } else if (code === KeyCodes.UP) {
        this.modifyIndexBy(-1);
      }
    }
  }

I'm still pretty new to testing, and I have no idea how I'd go about testing this piece. The method takes an event, so do I have to synthesize an event object and pass it in?

After that, do I just somehow test that this.modifyIndexBy() gets called?

This method doesn't return anything. Do I modify my code to be more testable?

Aucun commentaire:

Enregistrer un commentaire