Can anyone here comment on the quality of this test case? I am here testing for the exception should be thrown scenario. I mean it works but is it the correct way to unit test for the scenarios where the expectation is that exception should be thrown?
it('should throw exception if config.env.json is malformed', async () => {
// Arrange: beforeEach
const fakeFsStub = sinon.stub(File, 'readFileAsyc');
fakeFsStub.withArgs('./src/configuration/config.json').returns(mockConfig);
fakeFsStub.withArgs('./src/configuration/config.test.json').returns(FakePromise.resolve(`{"key"}`));
try {
// Act
await Configuration.getConfiguration('test');
chai.assert.fail('test case failed: [should throw exception if config.env.json is malformed]');
} catch (e) {
// Assert
chai.assert.equal('SyntaxError: Unexpected token } in JSON at position 6', e + '');
}
});