1 import Metric from '../lib/Metric';
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 class MetricInstance<D extends MetricSchema> extends Metric<D> {}
14 interface DefaultMetricSchema extends MetricSchema {
20 describe('Metric', () => {
21 it('does not throw when creating a metric with a valid name', () => {
22 const validNames = ['name', 'hello_there', 'aAAa_2bB'];
25 for (let i = 0; i < validNames.length; i++) {
26 const name = validNames[i];
29 new MetricInstance<DefaultMetricSchema>({ name, version }, metricsRequestService);
34 it('throws when creating a metric with an invalid name', () => {
35 const invalidNames = [
36 'ends_with_an_underscore_',
37 '123_starts_with_a_number',
38 'contains_special_characters!@£$%^&*()',
42 for (let i = 0; i < invalidNames.length; i++) {
43 const name = invalidNames[i];
46 new MetricInstance<DefaultMetricSchema>({ name, version }, metricsRequestService);