grafana/public/app/features/alerting/TestRuleResult.test.tsx
Hugo Häggmark 0598d60234
Tests: Adds throwUnhandledRejections to jest setup (#19398)
* Chore: Adds throwUnhandledRejections to jest setup

* Bring back @grafana/runtime import

* Fix broken metric metadata aggregation test
2019-09-25 05:10:11 -07:00

44 lines
1.0 KiB
TypeScript

import React from 'react';
import { TestRuleResult, Props } from './TestRuleResult';
import { DashboardModel } from '../dashboard/state';
import { shallow } from 'enzyme';
jest.mock('@grafana/runtime/src/services/backendSrv', () => ({
getBackendSrv: () => ({
post: jest.fn(),
}),
}));
const setup = (propOverrides?: object) => {
const props: Props = {
panelId: 1,
dashboard: new DashboardModel({ panels: [{ id: 1 }] }),
};
Object.assign(props, propOverrides);
const wrapper = shallow(<TestRuleResult {...props} />);
return { wrapper, instance: wrapper.instance() as TestRuleResult };
};
describe('Render', () => {
it('should render component', () => {
const { wrapper } = setup();
expect(wrapper).toMatchSnapshot();
});
});
describe('Life cycle', () => {
describe('component did mount', () => {
it('should call testRule', () => {
const { instance } = setup();
instance.testRule = jest.fn();
instance.componentDidMount();
expect(instance.testRule).toHaveBeenCalled();
});
});
});