Writing unit tests for exception should be thrown case 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 () =&gt; {
  // 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 + '');
  }
});
You should be using the Chai assert.throws operator instead (http://www.chaijs.com/api/assert/#method_throwsO so your code might look like:

it('should throw exception if config.env.json is malformed', async () =&gt; {
  // 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"}`));

  chai.assert.throws( () =&gt; {
      // Act
      await Configuration.getConfiguration('test');
    }, 
    SyntaxError,
    'test case failed: [should throw exception if config.env.json is malformed]'
  );

});


Also it is not generally a good idea to test the string returned by an exception. There is no guarantee that it will be the same between different browsers or different browser versions. If you need to check the position you should use the lineNumber and columnNumber properties of SyntaxError (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)

Lastly concating with '' to perform a string conversion is not the best option either use e.messaage attribute of an exception or the toString() method available on pretty much all objects.