jeudi 22 mars 2018

How to test javascript code

I need help to test my Javascript code. I have a method called update, which will move my enemies for my game around the screen.

constructor(game, x, y, bulletLayer, frame) {
    super(game, x, y, 'enemy', frame);
    this.bounceTick = Math.random() * 2; }

update() {
    this.bounceTick += .02;
    this.y += Math.sin(this.bounceTick) * 1;
} 

When writing my test for it this is what I have attempted to do.

it("moves position correctly", function() {
this.bounceTick = 2;
enemy.update();
assert.equal(Math.sin(this.bounceTick) *1);
 });

This is the error I get- AssertionError: expected NaN to equal undefined.

How would I go about writing a test for the update code to make sure my enemy is moving correctly? I know that I am supposed to set bounceTick to a stationary number since in the class it is being calculated as Math.random() * 2

Aucun commentaire:

Enregistrer un commentaire