Chore: Upgrade Jest to latest (#25591)

* Chore: Upgrade Jest to latest

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* Chore: reduces strict null errors

Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>
This commit is contained in:
Arve Knudsen
2020-06-15 13:06:37 +02:00
committed by GitHub
parent b1dee9392b
commit 91c24e1f56
11 changed files with 1415 additions and 66 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { QueryOperationRow } from './QueryOperationRow';
import { shallow, mount } from 'enzyme';
import { mount, shallow } from 'enzyme';
import { act } from 'react-dom/test-utils';
describe('QueryOperationRow', () => {
@@ -17,6 +17,7 @@ describe('QueryOperationRow', () => {
describe('callbacks', () => {
it('should not call onOpen when component is shallowed', async () => {
const onOpenSpy = jest.fn();
// @ts-ignore strict null error, you shouldn't use promise like approach with act but I don't know what the intention is here
await act(async () => {
shallow(
<QueryOperationRow onOpen={onOpenSpy}>
@@ -38,10 +39,13 @@ describe('QueryOperationRow', () => {
const titleEl = wrapper.find({ 'aria-label': 'Query operation row title' });
expect(titleEl).toHaveLength(1);
// @ts-ignore strict null error, you shouldn't use promise like approach with act but I don't know what the intention is here
await act(async () => {
// open
titleEl.first().simulate('click');
});
// @ts-ignore strict null error, you shouldn't use promise like approach with act but I don't know what the intention is here
await act(async () => {
// close
titleEl.first().simulate('click');

View File

@@ -2,6 +2,8 @@ import React from 'react';
import { shallow } from 'enzyme';
import { MetricSelect } from './MetricSelect';
import { LegacyForms } from '@grafana/ui';
import { expect } from '../../../../test/lib/common';
const { Select } = LegacyForms;
describe('MetricSelect', () => {
@@ -32,16 +34,15 @@ describe('MetricSelect', () => {
variables: [],
};
const wrapper = shallow(<MetricSelect {...props} />);
wrapper
.find(Select)
.props()
.onChange({ value: 'foo' });
expect(
wrapper
.find(Select)
.props()
.noOptionsMessage()
).toEqual('No options found');
const select = wrapper.find(Select);
select.props().onChange({ value: 'foo' });
expect(select.props().noOptionsMessage).toBeDefined();
// @ts-ignore typescript doesn't understand that noOptionsMessage can't be undefined here
const noOptionsMessage = select.props().noOptionsMessage();
expect(noOptionsMessage).toEqual('No options found');
expect(spyOnChange).toHaveBeenCalledWith('foo');
});
});