1 import Histogram from '../lib/Histogram';
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('Histogram', () => {
26 jest.clearAllTimers();
27 jest.setSystemTime(time);
34 it('construct correct metric report', () => {
37 const counter = new Histogram<DefaultMetricSchema>({ name, version }, metricsRequestService);
39 const value = 123.456;
40 counter.observe({ Value: value, Labels: { foo: 'bar' } });
42 expect(metricsRequestService.report).toHaveBeenCalledWith({
45 Timestamp: time.getTime() / 1000,
48 Labels: { foo: 'bar' },