Я кодирую игру в блэкджек в JS и пытаюсь провести модульные тесты в своем коде. Я использую Jest Js для выполнения тестов. Я хочу протестировать одну функцию - функцию takeDeposit, которая берет новый депозит от игрока. В этой функции я использую пакет readline-syn c.
Тест, который я пытаюсь сделать:
const { takeNewDeposit, minBetOfTheTable } = require('../../utils/takeDeposit')
test('taking an integer value as deposit', () => {
let deposit = takeNewDeposit()
expect(deposit).toBeGreaterThanOrEqual(minBetOfTheTable)
})
Я получаю это сообщение: FAIL tests / unit / takeDeposit.test. js
Call retries were exceeded
at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:230:21)
Код тестируемого кода:
var readlineSync = require('readline-sync')
const minBetOfTheTable = 25 // the minimun value that someone can bet at this table
const takeInteger = function takeInteger() { // function that takes an integer from the user
let userInput = readlineSync.questionInt('How much do you want to deposit on your bank? \nU$',{
limit: /\.txt$/i,
limitMessage: "Please, input an integer number."
})
return userInput
}
const takeDeposit = function takeDeposit() {
let bet = takeInteger()
while (bet < minBetOfTheTable) { // the deposit need to be higher than the minBetOfTheTable, so the player can bet at least one time
console.log(`Please, input a value higher than U$${minBetOfTheTable}`)
bet = takeInteger()
}
return bet
}
const takeNewDeposit = function takeNewDeposit(bank) {
let deposit = takeInteger()
while (bank.total + deposit < minBetOfTheTable) { // the deposit need to be higher than the minBetOfTheTable, so the player can bet at least one time
console.log(`Please, input a value higher than U$${minBetOfTheTable - bank.total}`)
deposit = takeInteger()
}
return deposit
}
module.exports = {
takeDeposit,
minBetOfTheTable,
takeNewDeposit
}