@dip-in-milk/snake
Advanced tools
Comparing version 1.0.1-0 to 1.0.1-1
{ | ||
"name": "@dip-in-milk/snake", | ||
"version": "1.0.1-0", | ||
"version": "1.0.1-1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -48,3 +48,5 @@ import DIRECTION from './DIRECTION'; | ||
this.gameObjects.forEach((gameObject) => { | ||
gameObject.tick(); | ||
if ('tick' in gameObject) { | ||
gameObject.tick(); | ||
} | ||
}); | ||
@@ -51,0 +53,0 @@ } |
@@ -50,6 +50,2 @@ import DIRECTION from './DIRECTION'; | ||
tick() { | ||
throw new Error(`Method "tick" should be implemented for ${this.constructor.name}`); | ||
} | ||
/** | ||
@@ -56,0 +52,0 @@ * Being killed by a gameObject |
@@ -5,2 +5,3 @@ import Game from '../../src/Game'; | ||
import Pixel from '../../src/Pixel'; | ||
import Fruit from '../../src/Fruit'; | ||
@@ -48,7 +49,15 @@ jest.mock('../../src/Snake'); | ||
describe('#tick', () => { | ||
game.gameObjects = [ | ||
new Fruit(), | ||
new Snake(), | ||
]; | ||
game.tick(); | ||
it('should call player.tick() for each gameObject', () => { | ||
it('should call player.tick() for each gameObject which has tick method', () => { | ||
game.gameObjects.forEach((gameObject) => { | ||
expect(gameObject.tick).toBeCalled(); | ||
if (gameObject.tick) { | ||
expect(gameObject.tick).toBeCalledWith(); | ||
} else { | ||
expect(gameObject.tick).toBe(undefined); | ||
} | ||
}); | ||
@@ -55,0 +64,0 @@ }); |
@@ -75,8 +75,2 @@ import GameObject from '../../src/GameObject'; | ||
}); | ||
describe('#tick', () => { | ||
it('should throw an Error', () => { | ||
expect(gameObject.tick).toThrowError(); | ||
}); | ||
}); | ||
}); |
19862
637