44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import { resetContext } from 'kea' ;
8-
97import { JSON_HEADER as headers } from '../../../../common/constants' ;
10- import { mockHttpValues } from '../../__mocks__/http_logic.mock ' ;
8+ import { LogicMounter , mockHttpValues } from '../../__mocks__' ;
119
12- import { TelemetryLogic } from './' ;
10+ import { TelemetryLogic } from './telemetry_logic ' ;
1311
1412describe ( 'Telemetry logic' , ( ) => {
13+ const { mount, getListeners } = new LogicMounter ( TelemetryLogic ) ;
1514 const { http } = mockHttpValues ;
1615
1716 beforeEach ( ( ) => {
1817 jest . clearAllMocks ( ) ;
19- resetContext ( { } ) ;
20- TelemetryLogic . mount ( ) ;
18+ mount ( ) ;
2119 } ) ;
2220
2321 describe ( 'sendTelemetry' , ( ) => {
@@ -36,11 +34,7 @@ describe('Telemetry logic', () => {
3634
3735 it ( 'throws an error if the telemetry endpoint fails' , async ( ) => {
3836 http . put . mockImplementationOnce ( ( ) => Promise . reject ( ) ) ;
39-
40- // To capture thrown errors, we have to call the listener fn directly
41- // instead of using `TelemetryLogic.actions.sendTelemetry` - this is
42- // due to how Kea invokes/wraps action fns by design.
43- const { sendTelemetry } = ( TelemetryLogic . inputs [ 0 ] as any ) . listeners ( { actions : { } } ) ;
37+ const { sendTelemetry } = getListeners ( ) ;
4438
4539 await expect ( sendTelemetry ( { action : '' , metric : '' , product : '' } ) ) . rejects . toThrow (
4640 'Unable to send telemetry'
0 commit comments