Test functions cannot both take a 'done' callback
Full error message
I'm trying to create a simple test with nestjs, and I'm getting this error
Test functions cannot both take a 'done' callback and return something. Either use a 'done' callback, or return a promise.
Returned value: Promise {}
The unit test is so simple, but I get an error when I use done();
it('throws an error if a user signs up with an email that is in use', async (done) => {
fakeUsersService.find = () => Promise.resolve([{ id: 1, email: 'a', password: '1' } as User]);
try {
await service.signup('[email protected]', 'asdf');
} catch (err) {
done();
}
});Solutionsource: stackoverflow \u2197
You are combining Async/Await and Done. Either use asnyc/await, or done. it('throws an error if user signs up with email that is in use', async () => { try { await service(); expect(...); } catch (err) { } }); or use the done format it('throws an error if user signs up with email that is in use', (done) => { ... service() .then( ...) {} .catch( ...) {} } done(); });
API access
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/d56540652a1cd46034851d8be94bffe72777ce85b7ed1ba68cd40e2a717eb060hash \u00b7 d56540652a1cd46034851d8be94bffe72777ce85b7ed1ba68cd40e2a717eb060