telemetryClient.test.ts
TLDR
This file contains a test for the trackEvent
method in the TelemetryClient
class. It checks if the trackEvent
method and the pageVisited
method of the TelemetryClient
class call the appropriate functions when a RudderTelemetryHandler
is attached to the TelemetryClient
.
Methods
trackEvent
The trackEvent
method is a function of the TelemetryClient
class. It takes two parameters: the event name and the event type. This method is called to track events in the telemetry system.
pageVisited
The pageVisited
method is a function of the TelemetryClient
class. It takes two parameters: the page name and the page type. This method is called to track page visits in the telemetry system.
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import '@testing-library/jest-dom'
import TelemetryClient from './telemetryClient'
describe('trackEvent', () => {
const track = jest.fn()
const page = jest.fn()
test('should call Rudder\'s track when a RudderTelemetryHandler is attached to TelemetryClient', () => {
TelemetryClient.setTelemetryHandler()
TelemetryClient.trackEvent('test', 'onClick')
TelemetryClient.pageVisited('focalboard', 'test')
expect(track).not.toHaveBeenCalled()
expect(page).not.toHaveBeenCalled()
TelemetryClient.setTelemetryHandler({trackEvent: track, pageVisited: page})
TelemetryClient.trackEvent('test', 'onClick')
TelemetryClient.pageVisited('focalboard', 'test')
expect(track).toHaveBeenCalledTimes(1)
expect(page).toHaveBeenCalledTimes(1)
})
})