{"id":508,"hash":"d56540652a1cd46034851d8be94bffe72777ce85b7ed1ba68cd40e2a717eb060","pattern":"Test functions cannot both take a &#39;done&#39; callback","full_message":"I'm trying to create a simple test with nestjs, and I'm getting this error\n\nTest functions cannot both take a 'done' callback and return something. Either use a 'done' callback, or return a promise.\n\nReturned value: Promise {}\n\nThe unit test is so simple, but I get an error when I use done();\n\nit('throws an error if a user signs up with an email that is in use', async (done) => {\nfakeUsersService.find = () => Promise.resolve([{ id: 1, email: 'a', password: '1' } as User]);\ntry {\n  await service.signup('asdf@asdf.com', 'asdf');\n} catch (err) {\n  done();\n}\n});","ecosystem":"npm","package_name":"unit-testing","package_version":null,"solution":"You are combining Async/Await and Done.\n\nEither use asnyc/await, or done.\n\nit('throws an error if user signs up with email that is in use', async () => {\n    try {\n        await service();\n        expect(...);\n    } catch (err) {\n    }\n});\n\nor use the done format\n\nit('throws an error if user signs up with email that is in use', (done) => {\n    ...\n    service()\n     .then( ...) {}\n     .catch( ...) {}\n    }\n    done();\n});","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/70884240/test-functions-cannot-both-take-a-done-callback","votes":40,"created_at":"2026-04-19T04:51:16.276291+00:00","updated_at":"2026-04-19T04:51:16.276291+00:00"}