-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I had to make edits after accepting suggestions. I also added the tests for the corresponding error handling that was added.
- Loading branch information
1 parent
0ede789
commit 77e519b
Showing
3 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/enterprise_search/common/__mocks__/flush_promises.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* | ||
* This function ends the current event loop which will give all promises a chance | ||
* to complete. It is similar to calling `setTimeout` without specifying a length of | ||
* time. | ||
* | ||
* For example: | ||
* // Mock http.get to return a rejected promise immediately | ||
* (HttpLogic.values.http.get as jest.Mock).mockReturnValue(Promise.reject('An error occured')); | ||
* // Call an action, which calls http.get and awaits it | ||
* CredentialsLogic.actions.fetchCredentials(2); | ||
* // Give the http.get promise a chance to be rejected | ||
* await flushPromises(); | ||
* // Make assertions | ||
* expect(flashAPIErrors).toHaveBeenCalledWith('An error occured'); | ||
*/ | ||
export function flushPromises() { | ||
return new Promise((resolve) => setImmediate(resolve)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters