Closed schiller-manuel closed 6 years ago
I'm sure I'm probably missing the point here, but if you simply provide a different name ("index.customFunction") that will call another function.
Sure I could actually write this function to a file, but I'd like to create a function locally inside my test and then pass it to virtual-alexa, e.g.:
const myTestHandler = (event, context, callback) => {
const alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(mockHandler);
alexa.execute();
};
const virtualAlexa = VirtualAlexa.Builder()
.handler(myTestHandler)
.interactionModelFile('model.json')
.create();
I see now - that's a nice use-case. I added a PR for this, along with a pre-release version you can try out: 0.3.11-0.
The PR is here: #22
An example of how to use it is here: https://github.com/bespoken/virtual-alexa/blob/3d743630c71f76794f7bd288ccc5e4c298414cd2/test/VirtualAlexaTest.ts#L507
Very similar to what you have above. Give it a try and let me know how it goes.
works perfectly, thanks for the rapid implementation :)
Awesome - glad to hear it. Thanks for the suggestion, and thanks also for the other PR.
How can I pass a handler function directly into virtual-alexa (instead of passing a string)?
My use case: I need to mock several resources when running the tests locally, hence I want to use a custom handler function purely for testing.