Amazon Alexaask-sdk

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)
        }
      })
})

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts