Skip to content

Commit

Permalink
Add test for move method
Browse files Browse the repository at this point in the history
  • Loading branch information
Lloople committed Apr 21, 2019
1 parent 3d44082 commit 6496c74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/components/Board.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
this.isGameOver = true;
},
move() {
// Missing test
let nextBodyPosition = this.snakeHead;
let nextHeadPosition = this.guessHeadNewPosition();
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/board.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,24 @@ describe('Board', () => {
});
});

test('it moves all the body parts in the correct direction', () => {
const board = shallowMount(Board);

// Remove the default snake from the board.
board.vm.cleanSnake();

board.setData({
direction: DIRECTION.UP,
snakeHead: '5,5',
snakeBody: ['5,6', '5,7', '4,7']
});

board.vm.move();

expect(board.vm.snakeHead).toBe('5,4');
expect(board.vm.snakeBody[0]).toBe('5,5');
expect(board.vm.snakeBody[1]).toBe('5,6');
expect(board.vm.snakeBody[2]).toBe('5,7');

});
});

0 comments on commit 6496c74

Please sign in to comment.