Two of my jest test suites are failing to run, I receive the errors “_player.default is not a constructor” and “_gameboard.default is not a constructor”.
I have a player class that I want to test:
export default class Player {
constructor(name) {
this.name = name;
this.isTurn = false;
this.isConsideringAttack = false;
this.gameboard = new Gameboard();
}
}
And a gameboard class:
export default class Gameboard {
constructor() {
this.board = [];
this.initialiseBoard();
}
}
The error I receive when I try to run the player test suite:
● Test suite failed to run
TypeError: _player.default is not a constructor
3 |
4 | const players = {
> 5 | user: new Player('user'),
| ^
6 | computer: new Player('computer'),
7 | };
8 |
at Object.<anonymous> (src/game.js:5:9)
at Object.<anonymous> (src/dragAndDrop.js:2:1)
The error I receive when I try to run the gameboard test suite:
● Test suite failed to run
TypeError: _gameboard.default is not a constructor
7 | this.isTurn = false;
8 | this.isConsideringAttack = false;
> 9 | this.gameboard = new Gameboard();
| ^
10 | }
11 |
12 | attack(x, y, gameboard) {
at new Player (src/factories/player.js:9:22)
at Object.<anonymous> (src/game.js:5:9)
at Object.<anonymous> (src/dragAndDrop.js:2:1)
I’m very new to Jest, I couldn’t find a fix for this despite spending a few hours searching. Any help would be appreciated.