Search code examples
testingautomationautomated-testse2e-testingtestcafe

Is it possible in TestCafe to expect errors to be thrown?


With t.skipJsError() I can easily skip (specified) JS errors.

Is there also the possibility to expect, if a certain error has been thrown? That would mean, that if the error is not thrown, the test will not succeed.

Thanks!


Solution

  • You can use a try-catch construction. For example:

    fixture('My fixture')
        .page('./index.html');
    test('First test', async t => {
      try {
        await t.click('button');
      } catch (e) {
        await t.expect(e.errStack).contains('Error:');
      }
    });