[Enterprise Search] Small test helper for expected async errors#88422
[Enterprise Search] Small test helper for expected async errors#88422cee-chen merged 2 commits intoelastic:masterfrom
Conversation
- Also hopefully a bit more descriptive on what's happening
…to use new helper
|
Requesting a review from @scottybollinger since I'm touching WS tests |
| export { rerender } from './enzyme_rerender.mock'; | ||
| // Note: shallow_useeffect must be imported directly as a file | ||
|
|
||
| export { expectedAsyncError } from './expected_async_error'; |
There was a problem hiding this comment.
Just btw, I know I'm getting a little loosey-goosey here with what should go into the __mocks__ folder, especially since this is definitely strictly a test helper and not a mock 😅 I'm definitely happy to revisit at some point if we just want a generic test helper folder, or if we want to split this up later at some point
There was a problem hiding this comment.
I'm not concerned about it.
|
FYI: I have 2 more Jest test related PRs coming after this. 1 that simplifies importing/mocking logic action/values from other logic files, and 1 final general cleanup PR. HOTYB! |
💚 Build SucceededMetrics [docs]
To update your PR or re-run it, just comment with: |
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| export const expectedAsyncError = async (promise: Promise<unknown>) => { |
There was a problem hiding this comment.
I like this a lot. I was imagining it'd have to be something more complex, but this is laser focused.
There was a problem hiding this comment.
Awesome! We can definitely extend it in the future if we need to is my thought, but maybe we won't have to.
|
Thanks y'all! Another PR coming here shortly 🎉 |
…) (#88492) * Add small helper to reduce boilerplate on async tests expected to throw - Also hopefully a bit more descriptive on what's happening * Update all test files using the previous try/catch do nothing blocks to use new helper # Conflicts: # x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts
* Initial copy/paste of component tree Only does linting changes and lodash import * Replace withRouter HOC with hooks Use useLocation and no longer pass around history, using the KibanaLogic navigateToUrl method instead * Migrate LicenseCallout component * Update paths Also change name of component to OauthApplication as the default import was named that before * Remove conditional and passed in flash messages This is no longer needed with the Kibana syntax. Flash messages are set globally and only render when present. * Replace removed ConfirmModal In Kibana, we use the Eui components directly * Use internal tools for determining license * Fix a bunch of type issues * Remove telemetry settings section We no longer control telemetry in Workplace Search. It is handled by Kibana itself * Add SettingsSubNav component * Add route and update nav * Remove legacy AppView and sidenav * Clear flash messages globally * Remove global name change method call The global org name is not used anywhere outside of this section so we no longer need to update the global organization object as it is re-fetched when this section is entered. Previously, we displayed the org name in the sidebar but that has been removed in Kibana * Refactor saveUpdatedConfig We recently split out the logic from SourceLogic to the new AddSourceLogic and in settings, we were calling the saveSourceConfig method from the SourceLogic (now in AddSourceLogic) file and passing a callback that set the flash messages from that component’s state. Now, we set the flash messages globally and no longer need to have a saveUpdatedConfig method in the logic file, but can call it directly in the component and the flash messages will be set globally. * Update logic file to use global flash messages * Update server routes * Replace Rails http with kibana http * Fix subnav * Update routes to use consistent syntax We use this method across both Enterprise Search products in Kibana * Shorten nav item copy This would be the only place in the sidebar with a nav item breaking to a second line. * Fix some random typos * Replace React Router Link with helper * Add i18n * Remove redundant clearing of flash messages This happens automatically now in the global flash messages logic; route changes trigger clearing of messages * Add unit tests for components * Add tests for router * Store oauthApplication in mock for reuse * Add tests for SettingsLogic * Fix typo * Remove unncessary imports Copied from this PR: #88525 * Refactor to use new helpers when mocking See #88494 * Update logic test to use error helper See #88422 * Fix type issue * Fix whitespace lint issue Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
Follow up to this conversation we had here: #88250 (comment)
Byron made an excellent point that the try/catch boilerplate around expected errors isn't super intuitive and is confusing at first glance (especially the comment, probably). I thought it would help us to DRY out a very small helper which serves a few purposes:
expect()s withincatch, which as we've already discussed previously can lead to false positive test resultsLet me know what y'all think! Just IMO, 50+ deleted lines is worth 💪
Checklist