Ad
Test Method Is Overspecified
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?
Ad
Answer
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;
})
});
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad