-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add client side service mocks #32999
Conversation
return startContract; | ||
}; | ||
|
||
type MethodKeysOf<T> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this type definition is duplicated across all *.mock.ts
files I'd suggest to finally decide where to can place such helpers. We can do that in following PRs tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm definitely pro adding a file of "meta" types that are types used to create other types. This shouldn't have any types that are Kibana or even Node/Browser specific, but just generic types like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to introduce new entities in the codebase. how about to just place such helpers in typings/index.d.ts
? @joshdover @epixa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like an appropriate place to me.
return this; | ||
}); | ||
const MockBasePathService = basePathServiceMock.create(); | ||
const BasePathServiceConstructor = jest.fn().mockImplementation(() => MockBasePathService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine not to have *Constructor
as a part of *.mock.ts
. It's not widely used and it's easy to declare right at the place of use.
Pinging @elastic/kibana-platform |
1 similar comment
Pinging @elastic/kibana-platform |
💔 Build Failed |
💔 Build Failed |
💚 Build Succeeded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mocks themselves look good to me and I like the clarity of the pattern you've introduced.
The enforcement of accurate mocks via the type system is great. Thanks for spending the time updating Jest to make that possible.
@@ -17,6 +17,7 @@ | |||
* under the License. | |||
*/ | |||
|
|||
import { basePathServiceMock } from '../../../../../core/public/base_path/base_path.mock'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about exporting mocks at the root level of core/public
? I imagine many plugins are going to be using these mocks and it'd best if they don't have to dig into the filesystem of core. I think adding a core/public/mocks.ts
file that exports only the mocks that are needed (core start contracts) would be ideal.
💔 Build Failed |
💚 Build Succeeded |
|
||
const createStartContractMock = () => { | ||
const startContract: jest.Mocked<NotificationsStart> = { | ||
// we have to suppress type errors until decide how to mock es6 class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created an issue #33396
* Add client side service mocks * remove ab obsolete test snapshot * put back accidentally removed type definition * define MethodKeysOf, PublicMethodsOf on project level * export src/core/public service mocks * export src/core/server service mocks
* Add client side service mocks * remove ab obsolete test snapshot * put back accidentally removed type definition * define MethodKeysOf, PublicMethodsOf on project level * export src/core/public service mocks * export src/core/server service mocks
Summary
Issue #31486
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers