Reputation: 7196
I have this before
function in my test:
before((done) => {
const cognito = new Cognito();
return cognito.authUser(
'[email protected]',
'password',
)
.then((res) => {
AuthToken += res.AuthenticationResult.IdToken;
done();
})
.catch((err) => {
done(err);
});
});
It throws this error:
Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both.
I thought this may have been the fix:
before((done) => {
const cognito = new Cognito();
return new Promise(function(resolve) {
cognito.authUser(
'[email protected]',
'password',
)
})
.then((res) => {
AuthToken += res.AuthenticationResult.IdToken;
done();
})
.catch((err) => {
done(err);
});
});
but it gives me this error:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
How do I resolve this?
Upvotes: 2
Views: 133
Reputation: 4174
The error explains a little bit.
You can't use both callback and a return.
You have 2 options:
callback (the
done
parameter)
before((done) => {
const cognito = new Cognito();
cognito.authUser(
'[email protected]',
'password',
)
.then((res) => {
AuthToken += res.AuthenticationResult.IdToken;
done();
})
.catch((err) => done(err));
});
or
Return promise
before(() => {
const cognito = new Cognito();
return cognito.authUser(
'[email protected]',
'password',
)
.then((res) => {
AuthToken += res.AuthenticationResult.IdToken;
})
});
Upvotes: 2