0

This is my code

it('fires change event when calling blah.doSomethingThatFiresChange', async function (done) {
  const blah = await getBlah()
  blah.on('change', () => done())
  blah.doSomethingThatFiresChange()
})

And I have the folowing error

Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both.

But I am not returning any promise

If I change mu code for

it('fires change event when calling blah.doSomethingThatFiresChange', async function (done) {
  const blah = await getBlah()
  //blah.on('change', () => done())
  blah.doSomethingThatFiresChange()
})

I have a timeout

Ajouve
  • 9,735
  • 26
  • 90
  • 137
  • 1
    "_But I am not returning any promise_" - Yes you do. You pass an `async function`, [which always returns a Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function#return_value). – Ivar May 16 '23 at 09:17
  • OK, I understand Is there any way to handle the event result and async function in this case ? – Ajouve May 16 '23 at 09:20
  • One option could be to not use an `async function` and use the `.then()` of the value returned by `getBlah()` instead of `await`. Like `getBlah().then(blah => { blah.on('change', () => done()); blah.doSomethingThatFiresChange(); })` – Ivar May 16 '23 at 11:11
  • Does this answer your question?https://stackoverflow.com/questions/41761683/why-am-i-getting-error-resolution-method-is-overspecified – Lin Du May 17 '23 at 07:08
  • Thanks, It was already done with promise before, but I would like to change for async as chalenge – Ajouve May 17 '23 at 07:26

0 Answers0