How to test the progressive response API call by ask-sdk with jest
We often use a “progressive response” to the speech any content to wait for the long task. And we […]
広告ここから
広告ここまで
目次
We often use a “progressive response” to the speech any content to wait for the long task.
And we want to test the API call by jest.
Create mock client by jest
We can mock the serviceClientFactory
class by the following code.
const mockClient= jest.fn()
handlerInput.serviceClientFactory = {
getDirectiveServiceClient: () => ({
enqueue: mockClient
})
} as any
And when call your skill’s request handler, we can test the mock function.
it('test', async () => {
const result = await YOUR_REQUEST_HANDLER.handle(handlerInput)
expect(mockClient).toHaveBeenCalledWith({
"directive": {
"speech": "<speak><p>Hello! Hello!!</p></speak>",
"type": "VoicePlayer.Speak"
},
"header": {
"requestId": expect.any(String)
}
})
})