1 import Counter from '../lib/Counter';
2 import MetricsApi from '../lib/MetricsApi';
3 import MetricsRequestService from '../lib/MetricsRequestService';
4 import type MetricSchema from '../lib/types/MetricSchema';
6 jest.mock('../lib/MetricsApi');
7 const metricsApi = new MetricsApi();
9 jest.mock('../lib/MetricsRequestService');
10 const metricsRequestService = new MetricsRequestService(metricsApi, { reportMetrics: true });
12 interface DefaultMetricSchema extends MetricSchema {
18 const time = new Date('2020-01-01');
20 describe('Counter', () => {
26 jest.clearAllTimers();
27 jest.setSystemTime(time);
34 it('construct correct metric report', () => {
37 const counter = new Counter<DefaultMetricSchema>({ name, version }, metricsRequestService);
39 counter.increment({ foo: 'bar' });
41 expect(metricsRequestService.report).toHaveBeenCalledWith({
44 Timestamp: time.getTime() / 1000,
47 Labels: { foo: 'bar' },