Skip to content

Commit

Permalink
Add test to ensure error gets thrown when inner function throws
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Nov 27, 2019
1 parent 96e3855 commit 4d30e0f
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,17 @@ test('createAPIKey() returns an API key when security is enabled', async () => {
const createAPIKeyResult = await constructorCall.createAPIKey();
expect(createAPIKeyResult).toEqual({ created: true, result: { api_key: '123', id: 'abc' } });
});

test('createAPIKey() throws when security plugin createAPIKey throws an error', async () => {
const factory = new AlertsClientFactory({
...alertsClientFactoryParams,
securityPluginSetup: securityPluginSetup as any,
});
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
const constructorCall = jest.requireMock('../alerts_client').AlertsClient.mock.calls[0][0];

securityPluginSetup.authc.createAPIKey.mockRejectedValueOnce(new Error('TLS disabled'));
await expect(constructorCall.createAPIKey()).rejects.toThrowErrorMatchingInlineSnapshot(
`"TLS disabled"`
);
});

0 comments on commit 4d30e0f

Please sign in to comment.