Skip to content

Commit

Permalink
[Uptime] Remove prototype overwrite in unit test (elastic#73709)
Browse files Browse the repository at this point in the history
* Remove prototype overwrite in unit test.

* Wrap calls to prototype functions with jest.spyOn.

* add additional component test helpers

* add test examples

* uptime testing utils remove custom prefix from props and parameter options

* skip executed step tests

* adjust MlJobLink test

* add testing util interfaces

* Move updated test files to correct locations.

* Move other test file to correct location.

* Revert unintended changes from merge.

* Revert unintended changes from merge.

* update mock core

* combine wrappers into one custom render function

* Move mock helpers to helper file. Update snapshots.

* Refactor tests to use RTL over enzyme.

* Refactor \`PingHistogram\` component tests to prefer RTL to Enzyme.

* Drop obsolete snapshot file.

* Remove obsolete file leftover from merge error.

* Fix outdated import path.

* Prefer custom render to vanilla.

* Fix formatting issue uncovered by unit test, and update test assertion.

* Add test for single location.

Co-authored-by: Dominique Clarke <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
3 people authored Jan 12, 2021
1 parent 1ab46af commit 1094274
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 627 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
*/

import React from 'react';
import DateMath from '@elastic/datemath';
import { PingHistogramComponent, PingHistogramComponentProps } from './ping_histogram';
import { renderWithRouter, shallowWithRouter, MountWithReduxProvider } from '../../../lib';
import moment from 'moment';
import { render } from '../../../lib/helper/rtl_helpers';
import { mockDataPlugin, mockMoment, mockMomentTimezone } from '../../../lib/helper/test_helpers';

describe('PingHistogram component', () => {
let dateMathSpy: any;
beforeAll(() => {
moment.prototype.fromNow = jest.fn(() => 'a year ago');
mockMoment();
mockMomentTimezone();
mockDataPlugin();
dateMathSpy = jest.spyOn(DateMath, 'parse');
dateMathSpy.mockReturnValue(20);
});

afterAll(() => {
jest.clearAllMocks();
});

const props: PingHistogramComponentProps = {
Expand Down Expand Up @@ -48,18 +58,13 @@ describe('PingHistogram component', () => {
},
};

it('shallow renders the component without errors', () => {
const component = shallowWithRouter(<PingHistogramComponent {...props} />);
expect(component).toMatchSnapshot();
});

it('renders the component without errors', () => {
const component = renderWithRouter(
<MountWithReduxProvider>
<PingHistogramComponent {...props} />
</MountWithReduxProvider>
const { getByLabelText, getByText } = render(<PingHistogramComponent {...props} />);
expect(getByText('Pings over time'));
expect(
getByLabelText(
'Bar Chart showing uptime status over time from 15 minutes ago to 15 minutes ago.'
)
);

expect(component).toMatchSnapshot();
});
});
Loading

0 comments on commit 1094274

Please sign in to comment.