odin-codespace/battleship/tests/ship.test.js

28 lines
594 B
JavaScript
Raw Normal View History

2024-03-15 12:12:11 -04:00
import { Ship } from '../src/components/ship';
2024-02-20 14:22:30 -05:00
it('should have length, number of times hit, and if sunk', () => {
// Small ship
2024-03-15 12:12:11 -04:00
const _ship = new Ship(2);
2024-02-20 14:22:30 -05:00
expect(_ship).toEqual({
length: 2,
hits: 0,
2024-03-15 12:12:11 -04:00
});
});
2024-02-20 14:22:30 -05:00
it('if hit, hit count should increase', () => {
const _ship = new Ship(2);
_ship.hit();
expect(_ship.hits).toBe(1);
2024-03-15 12:12:11 -04:00
});
2024-02-20 14:22:30 -05:00
it('is not sunk', () => {
const _ship = new Ship(2);
2024-03-15 12:12:11 -04:00
expect(_ship.isSunk()).toBeFalsy();
});
2024-02-20 14:22:30 -05:00
it('is sunk', () => {
const _ship = new Ship(2);
_ship.hits = 2;
2024-03-15 12:12:11 -04:00
expect(_ship.isSunk()).toBeTruthy();
});