I'm trying to write a test case that catches an error "Error: Please provide pitchWidth and pitchHeight". But I cannot seem to get the expect to catch the throw as a successful test.
Code:
mocha.describe('testValidationOfBadInputData()', function() { mocha.it('init game fails on pitch height', async() => { let t1location = './init_config/team1.json' let t2location = './init_config/team2.json' let plocation = './test/input/badInput/badPitchHeight.json' // let badFn = await validation.initGame(t1location, t2location, plocation) expect(await validation.initGame(t1location, t2location, plocation)).to.throw() }) })
Output:
1) testValidationOfBadInputData()
init game fails on pitch height:
Error: Please provide pitchWidth and pitchHeight
at Object.validatePitch (lib/validate.js:56:11)
at Object.initiateGame (engine.js:18:12)
at Object.initGame (test/lib/validate_tests.js:9:29)
Other Attempts have also failed:
1)
expect(await validation.initGame(t1location, t2location, plocation)).to.throw(Error, 'Please provide pitchWidth and pitchHeight');
2)
expect(await validation.initGame.bind(t1location, t2location, plocation)).to.throw();
Not sure what I'm doing wrong and the documentation doesn't seem obvious. https://www.chaijs.com/api/bdd/#method_throw
async function initGame(t1, t2, p) { let team1 = await common.readFile(t1) let team2 = await common.readFile(t2) let pitch = await common.readFile(p) let matchSetup = engine.initiateGame(team1, team2, pitch) return matchSetup }
the above is the function I am calling.