Chore: Removes console outputs in FieldCache.test.ts (#45141)

ivana/prom-hints
Hugo Häggmark 3 years ago committed by GitHub
parent f67e02cb2f
commit f9bb0832ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      packages/grafana-data/src/dataframe/FieldCache.test.ts

@ -69,24 +69,33 @@ describe('FieldCache', () => {
}); });
describe('field retrieval', () => { describe('field retrieval', () => {
const frame = toDataFrame({ let fieldCache: FieldCache;
fields: [
{ name: 'time', type: FieldType.time, values: [100, 200, 300] }, beforeEach(() => {
{ name: 'name', type: FieldType.string, values: ['a', 'b', 'c'] }, const frame = toDataFrame({
{ name: 'value', type: FieldType.number, values: [1, 2, 3] }, fields: [
{ name: 'value', type: FieldType.number, values: [4, 5, 6] }, { name: 'time', type: FieldType.time, values: [100, 200, 300] },
], { name: 'name', type: FieldType.string, values: ['a', 'b', 'c'] },
{ name: 'value', type: FieldType.number, values: [1, 2, 3] },
{ name: 'value', type: FieldType.number, values: [4, 5, 6] },
],
});
// Because we're using duplicate field names in the test case, we need to disable the warning,
// so it doesn't show up in the test output
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
fieldCache = new FieldCache(frame);
consoleWarnSpy.mockRestore();
}); });
const ext = new FieldCache(frame);
it('should get the first field with a duplicate name', () => { it('should get the first field with a duplicate name', () => {
const field = ext.getFieldByName('value'); const field = fieldCache.getFieldByName('value');
expect(field!.name).toEqual('value'); expect(field!.name).toEqual('value');
expect(field!.values.toArray()).toEqual([1, 2, 3]); expect(field!.values.toArray()).toEqual([1, 2, 3]);
}); });
it('should return index of the field', () => { it('should return index of the field', () => {
const field = ext.getFirstFieldOfType(FieldType.number); const field = fieldCache.getFirstFieldOfType(FieldType.number);
expect(field!.index).toEqual(2); expect(field!.index).toEqual(2);
}); });
}); });

Loading…
Cancel
Save