I have something simple as this.
` it("should call promise", async (done) => {
const testPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Hello World!");
}, 200);
});
const result = await testPromise;
done();
}`
But I keep on getting the error " Error: Resolution method is overspecified. Specify a callback or return a Promise; not both.".
If I take out done() then the test times out.
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "ES6",
"noImplicitAny": false,
"types": ["node", "mocha","supertest"],
"typeRoots": [
"./node_modules/@types"
]
}
}
mocha.opts
--require ts-node/register
--reporter dot
--watch-extensions tsx,ts
test/**/*.ts
lovely found how to fix it remove done in the function param and at bottom and it works. As soon as you put the done in function param it goes haywire
Keep in mind also that async
functions automatically return a promise.
seems as long as you async
, and as @ScottFreeCode said, it returns promise, so we just skip calling done()
. works.
Removing done worked for me!
BEFORE:
AFTER (Works!!):
getResponse function:
I had to removed the done
from the function parameter and the done()
of the function call
Before
before(async function (done) {
user = new User({ ...});
await user.save();
done()
});
After
before(async function () {
user = new User({ ...});
await user.save();
});
These works for me
I am having the same problem, and I need to user done, because I need to test that my promise fails. So I catch it, and then calling done, but getting this error.
it("...", async function (done) {
try {
await asyncFung(...);
done("The call should have failed")
} catch (error) {
if (error instanceof MyError) {
done()
} else {
done(error)
}
}
});
Most helpful comment
lovely found how to fix it remove done in the function param and at bottom and it works. As soon as you put the done in function param it goes haywire