66 */
77
88/**
9- * Combine all shared mock values/actions into a single obj
10- *
11- * NOTE: These variable names MUST start with 'mock*' in order for
12- * Jest to accept its use within a jest.mock()
13- */
14- import { mockFlashMessagesValues , mockFlashMessagesActions } from './flash_messages_logic.mock' ;
15- import { mockHttpValues } from './http_logic.mock' ;
16- import { mockKibanaValues } from './kibana_logic.mock' ;
17- import { mockLicensingValues } from './licensing_logic.mock' ;
18- import { mockTelemetryActions } from './telemetry_logic.mock' ;
19-
20- export const mockAllValues = {
21- ...mockKibanaValues ,
22- ...mockLicensingValues ,
23- ...mockHttpValues ,
24- ...mockFlashMessagesValues ,
25- } ;
26- export const mockAllActions = {
27- ...mockTelemetryActions ,
28- ...mockFlashMessagesActions ,
29- } ;
30-
31- /**
32- * Import this file directly to mock useValues with a set of default values for all shared logic files.
33- * Example usage:
34- *
35- * import '../../../__mocks__/kea'; // Must come before kea's import, adjust relative path as needed
36- */
37- jest . mock ( 'kea' , ( ) => ( {
38- ...( jest . requireActual ( 'kea' ) as object ) ,
39- useValues : jest . fn ( ( ) => ( { ...mockAllValues } ) ) ,
40- useActions : jest . fn ( ( ) => ( { ...mockAllActions } ) ) ,
41- } ) ) ;
42-
43- /**
44- * React component helpers
45- *
46- * Call this function to override a specific set of Kea values while retaining all other defaults
47- *
48- * Example usage:
49- *
50- * import { setMockValues } from '../../../__mocks__/kea.mock';
51- * import { SomeComponent } from './';
52- *
53- * it('some test', () => {
54- * setMockValues({ someValue: 'hello' });
55- * shallow(<SomeComponent />);
56- * });
57- */
58- import { useValues , useActions } from 'kea' ;
59-
60- export const setMockValues = ( values : object ) => {
61- ( useValues as jest . Mock ) . mockImplementation ( ( ) => ( { ...mockAllValues , ...values } ) ) ;
62- } ;
63- export const setMockActions = ( actions : object ) => {
64- ( useActions as jest . Mock ) . mockImplementation ( ( ) => ( { ...mockAllActions , ...actions } ) ) ;
65- } ;
66-
67- /**
68- * Kea logic helpers
69- *
709 * Call this function to mount a logic file and optionally override default values.
7110 * Automatically DRYs out a lot of cruft for us, such as resetting context, creating the
7211 * nested defaults path obj (see https://kea.js.org/docs/api/context#resetcontext), and
7312 * returning an unmount function
7413 *
7514 * Example usage:
7615 *
77- * import { LogicMounter } from '../../../__mocks__/kea.mock ';
16+ * import { LogicMounter } from '../../../__mocks__/kea_logic ';
7817 * import { SomeLogic } from './';
7918 *
8019 * const { mount, unmount } = new LogicMounter(SomeLogic);
@@ -86,7 +25,7 @@ export const setMockActions = (actions: object) => {
8625 */
8726import { resetContext , LogicWrapper } from 'kea' ;
8827
89- type LogicFile = LogicWrapper < any > ;
28+ type LogicFile = LogicWrapper < unknown > ;
9029
9130export class LogicMounter {
9231 private logicFile : LogicFile ;
0 commit comments