chore: tests mocking out setState is probably bad... let's make the test a little better,

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-03-23 15:28:07 +01:00
parent 9c1ee4d56b
commit 1c47698ad4
3 changed files with 7 additions and 11 deletions
+2 -1
View File
@@ -181,7 +181,8 @@ integrations:
# rawBaseUrl: https://ghe.example.net/raw
# token: ${GHE_TOKEN}
gitlab:
- host: gitlab.com
- host: lols.lols.com
apiBaseUrl: https://lols.lols.com/api
token: ${GITLAB_TOKEN}
### Example for how to add a bitbucket cloud integration
# bitbucketCloud:
-1
View File
@@ -150,7 +150,6 @@ async function getProjectConfig(targetPath, displayName) {
: undefined,
transformIgnorePatterns: [`/node_modules/(?:${transformIgnorePattern})/`],
...getRoleConfig(closestPkgJson?.backstage?.role),
};
@@ -20,7 +20,7 @@ import { BitriseBuildDetailsDialog } from './BitriseBuildDetailsDialog';
import { BitriseBuildResult } from '../../api/bitriseApi.model';
jest.mock('../BitriseArtifactsComponent', () => ({
BitriseArtifactsComponent: (_props: { build: string }) => <></>,
BitriseArtifactsComponent: (_props: { build: string }) => <>VISIBLE</>,
}));
describe('BitriseArtifactsComponent', () => {
@@ -42,18 +42,14 @@ describe('BitriseArtifactsComponent', () => {
expect(await rendered.findByTestId('btn')).toBeInTheDocument();
});
it('should change the state when the button is clicked', async () => {
const setOpen = jest.fn();
const useStateMock: any = (initState: any) => [initState, setOpen];
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
it('should open the modal when clicked to render the ArtifactsComponent', async () => {
const rendered = renderComponent();
const btn = await rendered.findByTestId('btn');
expect(await rendered.queryByText('VISIBLE')).not.toBeInTheDocument();
btn.click();
expect(setOpen).toHaveBeenCalled();
expect(rendered.getByText('VISIBLE')).toBeInTheDocument();
});
});