S
S
Svyatoslav Khusamov2018-06-26 11:38:30
JavaScript
Svyatoslav Khusamov, 2018-06-26 11:38:30

How to write a test to detect an error in an asynchronous function?

How to write a test to detect an error in an asynchronous function?
This option doesn't work:

assert.throw(async function() {
  await new Application().load('not-exists/path/to/app');
});

So far I've come up with this option:
try {
  await new Application().load('not-exists/path/to/app');
} catch (e) {
  assert.throw(function() {
    throw e;
  });
}

Is there a more elegant option?
UPD: What
exactly do I want to do in this
test ? And I need to make sure that an exception is thrown. I also want to use assert.throw(). UPD: The point is that assert.throw() doesn't allow you to test asynchronous functions. And therefore it was necessary to fence through try {} catch. This is strange to see because mocha has async/await support. Why is she not in chai? Or is it, where is it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question