mercredi 20 novembre 2019

Chai: throwing error on async/await when no parameter is passed

I am trying to test my code (Typescript) and it should throw when no parameter is passed

getID(ID) { if(!ID){throw new Error('stop js')} ....}

it('should fail if no ID', async () => { 

    expect(async () =>  await myService.getID() ).to.throw("stop js");
})

Based on the documentation the above should work however when I run the test I get

 1) myTest
   should fail if no groupId is passed:
 AssertionError: expected [Function] to throw an error

Aucun commentaire:

Enregistrer un commentaire