We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, having some trouble getting mock to work inside a class.
In the following code the mock is not being called at all when testing class
describe(`Mock test`, () => { it(`should mock call out from lambda`, done => { AWS.mock('Lambda', 'invoke', (params, callback) => callback(null, { Payload: {} })); executeLambda(lambda, event, (callbackErr, callbackDone) => { done(); }); }); });
This is an example of the class based approach i'm trying to test
module.exports = class MyIntent { async handle () { await this.invoke('myParam'); } invoke (paramName = { }) { const params = { paramName }; return Client.invoke(params) .promise() .then(response => JSON.parse(response.Payload) ); } };
The same code without class will run the mock when testing
exports.handle = event => { async function handle () { await invoke('myParam'); } function invoke (paramName = { }) { const params = { paramName }; return Client.invoke(params) .promise() .then(response => JSON.parse(response.Payload) ); } };
The text was updated successfully, but these errors were encountered:
@TooManyLogs I believe the issue here is that your class is not initialised and hence not picked up as a handler.
Change the export statement to:
class MyIntent { async handle () { await this.invoke('myParam'); } invoke (paramName = {}) { const params = { paramName }; return Client.invoke(params) .promise() .then(response => JSON.parse(response.Payload) ); }; } } module.exports = new MyIntent();
Sorry, something went wrong.
No branches or pull requests
Hi, having some trouble getting mock to work inside a class.
In the following code the mock is not being called at all when testing class
This is an example of the class based approach i'm trying to test
The same code without class will run the mock when testing
The text was updated successfully, but these errors were encountered: