eslint/excpect: should not be called conditionally
This commit fixes the error but not really the pattern. We should consider refactoring the tests following these guidelines: https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-conditional-expect.md
This commit is contained in:
parent
a1834ed76e
commit
3b8afeaf7d
3 changed files with 40 additions and 32 deletions
|
|
@ -886,8 +886,9 @@ describe('Click through all steps', () => {
|
|||
.spyOn(api, 'composeImage')
|
||||
.mockImplementation((body) => {
|
||||
let id;
|
||||
let expectedbody = {};
|
||||
if (body.image_requests[0].upload_request.type === 'aws') {
|
||||
expect(body).toEqual({
|
||||
expectedbody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -904,10 +905,10 @@ describe('Click through all steps', () => {
|
|||
},
|
||||
],
|
||||
customizations: customizations,
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f56';
|
||||
} else if (body.image_requests[0].upload_request.type === 'gcp') {
|
||||
expect(body).toEqual({
|
||||
expectedbody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -924,10 +925,10 @@ describe('Click through all steps', () => {
|
|||
},
|
||||
],
|
||||
customizations: customizations,
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f57';
|
||||
} else if (body.image_requests[0].upload_request.type === 'azure') {
|
||||
expect(body).toEqual({
|
||||
expectedbody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -946,10 +947,10 @@ describe('Click through all steps', () => {
|
|||
},
|
||||
],
|
||||
customizations: customizations,
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f58';
|
||||
} else if (body.image_requests[0].image_type === 'vsphere-ova') {
|
||||
expect(body).toEqual({
|
||||
expectedbody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -964,10 +965,10 @@ describe('Click through all steps', () => {
|
|||
},
|
||||
],
|
||||
customizations: customizations,
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f59';
|
||||
} else if (body.image_requests[0].image_type === 'guest-image') {
|
||||
expect(body).toEqual({
|
||||
expectedbody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -982,10 +983,10 @@ describe('Click through all steps', () => {
|
|||
},
|
||||
],
|
||||
customizations: customizations,
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f5a';
|
||||
} else if (body.image_requests[0].image_type === 'image-installer') {
|
||||
expect(body).toEqual({
|
||||
expectedbody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -1000,9 +1001,10 @@ describe('Click through all steps', () => {
|
|||
},
|
||||
],
|
||||
customizations: customizations,
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f5b';
|
||||
}
|
||||
expect(body).toEqual(expectedbody);
|
||||
|
||||
ids.unshift(id);
|
||||
return Promise.resolve({ id });
|
||||
|
|
|
|||
|
|
@ -1679,8 +1679,9 @@ describe('Click through all steps', () => {
|
|||
.spyOn(api, 'composeImage')
|
||||
.mockImplementation((body) => {
|
||||
let id;
|
||||
let excpectedBody = {};
|
||||
if (body.image_requests[0].upload_request.type === 'aws') {
|
||||
expect(body).toEqual({
|
||||
excpectedBody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -1721,10 +1722,10 @@ describe('Click through all steps', () => {
|
|||
'base-url': 'https://cdn.redhat.com/',
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f56';
|
||||
} else if (body.image_requests[0].upload_request.type === 'gcp') {
|
||||
expect(body).toEqual({
|
||||
excpectedBody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -1765,10 +1766,10 @@ describe('Click through all steps', () => {
|
|||
'base-url': 'https://cdn.redhat.com/',
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f57';
|
||||
} else if (body.image_requests[0].upload_request.type === 'azure') {
|
||||
expect(body).toEqual({
|
||||
excpectedBody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -1811,10 +1812,10 @@ describe('Click through all steps', () => {
|
|||
'base-url': 'https://cdn.redhat.com/',
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f58';
|
||||
} else if (body.image_requests[0].image_type === 'vsphere-ova') {
|
||||
expect(body).toEqual({
|
||||
excpectedBody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -1853,10 +1854,10 @@ describe('Click through all steps', () => {
|
|||
'base-url': 'https://cdn.redhat.com/',
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f59';
|
||||
} else if (body.image_requests[0].image_type === 'guest-image') {
|
||||
expect(body).toEqual({
|
||||
excpectedBody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -1895,10 +1896,10 @@ describe('Click through all steps', () => {
|
|||
'base-url': 'https://cdn.redhat.com/',
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f5a';
|
||||
} else if (body.image_requests[0].image_type === 'image-installer') {
|
||||
expect(body).toEqual({
|
||||
excpectedBody = {
|
||||
distribution: RHEL_8,
|
||||
image_name: 'my-image-name',
|
||||
image_description: 'this is a perfect description for image',
|
||||
|
|
@ -1937,9 +1938,10 @@ describe('Click through all steps', () => {
|
|||
'base-url': 'https://cdn.redhat.com/',
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
id = 'edbae1c2-62bc-42c1-ae0c-3110ab718f5b';
|
||||
}
|
||||
expect(body).toEqual(excpectedBody);
|
||||
|
||||
ids.unshift(id);
|
||||
return Promise.resolve({ id });
|
||||
|
|
|
|||
|
|
@ -100,27 +100,29 @@ describe('Images Table', () => {
|
|||
renderWithProvider(<Target composeId={compose.id} />, testElement, state);
|
||||
expect(row.cells[4]).toHaveTextContent(testElement.textContent);
|
||||
|
||||
let toTest = expect(row.cells[5]);
|
||||
// render the expected <ImageBuildStatus /> and compare the text content
|
||||
if (
|
||||
compose.created_at === '2021-04-27T12:31:12Z' &&
|
||||
compose.request.image_requests[0].upload_request.type === 'aws.s3'
|
||||
) {
|
||||
expect(row.cells[5]).toHaveTextContent('Expired');
|
||||
toTest.toHaveTextContent('Expired');
|
||||
} else {
|
||||
renderWithProvider(
|
||||
<ImageBuildStatus imageId={compose.id} isImagesTableRow={true} />,
|
||||
testElement,
|
||||
state
|
||||
);
|
||||
expect(row.cells[5]).toHaveTextContent(testElement.textContent);
|
||||
toTest.toHaveTextContent(testElement.textContent);
|
||||
}
|
||||
|
||||
toTest = expect(row.cells[6]);
|
||||
// render the expected <ImageLink /> and compare the text content for a link
|
||||
if (
|
||||
compose.created_at === '2021-04-27T12:31:12Z' &&
|
||||
compose.request.image_requests[0].upload_request.type === 'aws.s3'
|
||||
) {
|
||||
expect(row.cells[6]).toHaveTextContent('Recreate image');
|
||||
toTest.toHaveTextContent('Recreate image');
|
||||
} else {
|
||||
renderWithProvider(
|
||||
<BrowserRouter>
|
||||
|
|
@ -129,7 +131,7 @@ describe('Images Table', () => {
|
|||
testElement,
|
||||
state
|
||||
);
|
||||
expect(row.cells[6]).toHaveTextContent(testElement.textContent);
|
||||
toTest.toHaveTextContent(testElement.textContent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -304,25 +306,27 @@ describe('Clones table', () => {
|
|||
|
||||
for (const [index, row] of cloneRows.entries()) {
|
||||
// render AMIs in correct order
|
||||
let toTest = expect(row.cells[0]);
|
||||
switch (index) {
|
||||
case (0, 1, 3):
|
||||
expect(row.cells[0]).toHaveTextContent(clonesTableData.ami[index]);
|
||||
toTest.toHaveTextContent(clonesTableData.ami[index]);
|
||||
break;
|
||||
case 2:
|
||||
expect(row.cells[0]).toHaveTextContent('');
|
||||
toTest.toHaveTextContent('');
|
||||
break;
|
||||
}
|
||||
|
||||
// region cell
|
||||
expect(row.cells[1]).toHaveTextContent(clonesTableData.region[index]);
|
||||
|
||||
toTest = expect(row.cells[2]);
|
||||
// status cell
|
||||
switch (index) {
|
||||
case (0, 1, 3):
|
||||
expect(row.cells[2]).toHaveTextContent('Ready');
|
||||
toTest.toHaveTextContent('Ready');
|
||||
break;
|
||||
case 2:
|
||||
expect(row.cells[2]).toHaveTextContent('Image build failed');
|
||||
toTest.toHaveTextContent('Image build failed');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue