fix errors being logged during tests; de-lint

This commit is contained in:
Keith Grant
2020-02-07 11:55:09 -08:00
parent d06d4d5a8c
commit 8f77d15a31
8 changed files with 11 additions and 5 deletions

View File

@@ -10,8 +10,7 @@ function FormSubmitError({ error }) {
if (!error) {
return;
}
// check for field-specific errors from API
if (error.response?.data && typeof error.response.data === 'object') {
if (error?.response?.data && typeof error.response.data === 'object') {
const errorMessages = error.response.data;
setErrors(errorMessages);
if (errorMessages.__all__) {

View File

@@ -30,6 +30,12 @@ describe('<HostAdd />', () => {
});
test('handleSubmit should post to api', async () => {
HostsAPI.create.mockResolvedValueOnce({
data: {
...hostData,
id: 5,
},
});
await act(async () => {
wrapper.find('HostForm').prop('handleSubmit')(hostData);
});

View File

@@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { PageSection, Card } from '@patternfly/react-core';
import { CardBody } from '@components/Card';
import ContentError from '@components/ContentError';
import ContentLoading from '@components/ContentLoading';
import { InventoriesAPI, CredentialTypesAPI } from '@api';

View File

@@ -5,7 +5,6 @@ import { object } from 'prop-types';
import { CardBody } from '@components/Card';
import { InventoriesAPI, CredentialTypesAPI } from '@api';
import ContentLoading from '@components/ContentLoading';
import ContentError from '@components/ContentError';
import InventoryForm from '../shared/InventoryForm';
import { getAddedAndRemoved } from '../../../util/lists';

View File

@@ -14,6 +14,7 @@ describe('<OrganizationAdd />', () => {
description: 'new description',
custom_virtualenv: 'Buzz',
};
OrganizationsAPI.create.mockResolvedValueOnce({ data: {} });
await act(async () => {
const wrapper = mountWithContexts(<OrganizationAdd />);
wrapper.find('OrganizationForm').prop('onSubmit')(updatedOrgData, [], []);

View File

@@ -12,7 +12,7 @@ class TeamAdd extends React.Component {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleCancel = this.handleCancel.bind(this);
this.state = { error: '' };
this.state = { error: null };
}
async handleSubmit(values) {

View File

@@ -9,6 +9,7 @@ jest.mock('@api');
describe('<TeamAdd />', () => {
test('handleSubmit should post to api', async () => {
TeamsAPI.create.mockResolvedValueOnce({ data: {} });
const wrapper = mountWithContexts(<TeamAdd />);
const updatedTeamData = {
name: 'new name',

View File

@@ -13,6 +13,7 @@ describe('<UserAdd />', () => {
await act(async () => {
wrapper = mountWithContexts(<UserAdd />);
});
UsersAPI.create.mockResolvedValueOnce({ data: {} });
const updatedUserData = {
username: 'sysadmin',
email: 'sysadmin@ansible.com',