Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing 6 tests for my javascript code. I will provide my enemy class and the start of my test class. export default

I need help writing 6 tests for my javascript code. I will provide my enemy class and the start of my test class.

export default class Enemy extends Phaser.Sprite {

constructor(game, x, y, bulletLayer, frame) { super(game, x, y, 'enemy', frame);

// initialize your prefab here game.physics.enable(this, Phaser.Physics.ARCADE);

this.body.velocity.x = -175; this.bounceTick = Math.random() * 2;

this.bulletLayer = bulletLayer;

this.outOfBoundsKill = true;

this.willFire = Phaser.Utils.chanceRoll(50);

console.log(this.willFire);

if (this.willFire) { this.fireTimer = this.game.time.create(false); this.fireTimer.add(3500, this.fireShot, this); this.fireTimer.start(); } }

fireShot() { let bullet = this.bulletLayer.create(this.x, this.y, "enemyBullet"); this.game.physics.enable(bullet, Phaser.Physics.ARCADE); bullet.outOfBoundsKill = true; bullet.checkWorldBounds = true; bullet.body.velocity.x = -250; }

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

describe("Enemy", function () {

let assert = chai.assert;

let enemy;

//Test fixture, create the same kind of enemy before each test

beforeEach(function() {

// Stubbing out the features not used in constructor

let game = sinon.stub();

game.physics = sinon.stub();

game.physics.enable = sinon.stub();

let bullets = sinon.stub();

let screen = sinon.screen();

enemy = new Enemy(game, 0, 0, bullets,screen);

});

it("can be created", function () {

let enemy = new Enemy();

assert.isOk(true);

});

/*it("can be updated without any keys being pressed", function () {

enemy.update();

assert.isOk(true);

});*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions