From 1f91ebc65e35892c77f832f236a3d4beb54be5de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?=
=?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com>
Date: Wed, 19 Jul 2023 16:49:49 +0800
Subject: [PATCH] test: make testing more stable (#2277)
---
.../antd/checkbox/__tests__/checkbox.test.tsx | 26 +---
.../antd/input/__tests__/Input.test.tsx | 48 +------
.../__snapshots__/password.test.tsx.snap | 134 ------------------
.../antd/password/__tests__/password.test.tsx | 2 +-
.../antd/variable/__tests__/variable.test.tsx | 24 +---
5 files changed, 13 insertions(+), 221 deletions(-)
delete mode 100644 packages/core/client/src/schema-component/antd/password/__tests__/__snapshots__/password.test.tsx.snap
diff --git a/packages/core/client/src/schema-component/antd/checkbox/__tests__/checkbox.test.tsx b/packages/core/client/src/schema-component/antd/checkbox/__tests__/checkbox.test.tsx
index eb700cc08..89390103b 100644
--- a/packages/core/client/src/schema-component/antd/checkbox/__tests__/checkbox.test.tsx
+++ b/packages/core/client/src/schema-component/antd/checkbox/__tests__/checkbox.test.tsx
@@ -53,28 +53,16 @@ describe('Checkbox.Group', () => {
const option1 = screen.getByLabelText('选项1');
const option2 = screen.getByLabelText('选项2');
await userEvent.click(option1);
- expect(container.querySelectorAll('.ant-tag')).toMatchInlineSnapshot(`
- NodeList [
-
- 选项1
- ,
+ expect(Array.from(container.querySelectorAll('.ant-tag')).map((el) => el.innerHTML)).toMatchInlineSnapshot(`
+ [
+ "选项1",
]
`);
await userEvent.click(option2);
- expect(container.querySelectorAll('.ant-tag')).toMatchInlineSnapshot(`
- NodeList [
-
- 选项1
- ,
-
- 选项2
- ,
+ expect(Array.from(container.querySelectorAll('.ant-tag')).map((el) => el.innerHTML)).toMatchInlineSnapshot(`
+ [
+ "选项1",
+ "选项2",
]
`);
diff --git a/packages/core/client/src/schema-component/antd/input/__tests__/Input.test.tsx b/packages/core/client/src/schema-component/antd/input/__tests__/Input.test.tsx
index c5743bab3..a22a219f5 100644
--- a/packages/core/client/src/schema-component/antd/input/__tests__/Input.test.tsx
+++ b/packages/core/client/src/schema-component/antd/input/__tests__/Input.test.tsx
@@ -39,31 +39,7 @@ describe('Input.TextArea', () => {
fireEvent.change(textarea, { target: { value: 'Hello World, Hello World' } });
expect(textarea.value).toBe('Hello World, Hello World');
- expect(screen.getAllByText('Hello World, Hello World')).toMatchInlineSnapshot(`
- [
- ,
-
- Hello World, Hello World
-
,
-
- Hello World, Hello World
-
,
-
- Hello World, Hello World
-
,
- ]
- `);
+ expect(screen.getAllByText('Hello World, Hello World')).toHaveLength(4);
});
it('should not display undefined', () => {
@@ -88,16 +64,7 @@ describe('Input.URL', () => {
const input = container.querySelector('input') as HTMLInputElement;
await userEvent.type(input, 'https://www.nocobase.com');
expect(input.value).toBe('https://www.nocobase.com');
- expect(screen.getByText('https://www.nocobase.com')).toMatchInlineSnapshot(`
-
- https://www.nocobase.com
-
- `);
+ expect(screen.getByText('https://www.nocobase.com')).toBeInTheDocument();
});
it('should display the error when the value is invalid', async () => {
@@ -106,16 +73,7 @@ describe('Input.URL', () => {
const input = container.querySelector('input') as HTMLInputElement;
await userEvent.type(input, 'abcd');
expect(input.value).toBe('abcd');
- expect(screen.getByText('abcd')).toMatchInlineSnapshot(`
-
- abcd
-
- `);
+ expect(screen.getByText('abcd')).toBeInTheDocument();
// show error message
expect(screen.getByText('The field value is a invalid url').innerHTML).toBe('The field value is a invalid url');
diff --git a/packages/core/client/src/schema-component/antd/password/__tests__/__snapshots__/password.test.tsx.snap b/packages/core/client/src/schema-component/antd/password/__tests__/__snapshots__/password.test.tsx.snap
deleted file mode 100644
index 009e8a292..000000000
--- a/packages/core/client/src/schema-component/antd/password/__tests__/__snapshots__/password.test.tsx.snap
+++ /dev/null
@@ -1,134 +0,0 @@
-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-
-exports[`Password > should works with checkStrength 1`] = `
-
-`;
diff --git a/packages/core/client/src/schema-component/antd/password/__tests__/password.test.tsx b/packages/core/client/src/schema-component/antd/password/__tests__/password.test.tsx
index 4b358c53f..b87adb2e2 100644
--- a/packages/core/client/src/schema-component/antd/password/__tests__/password.test.tsx
+++ b/packages/core/client/src/schema-component/antd/password/__tests__/password.test.tsx
@@ -17,6 +17,6 @@ describe('Password', () => {
const { container } = render();
const input = container.querySelector('input') as HTMLInputElement;
fireEvent.change(input, { target: { value: '123456' } });
- expect(container).toMatchSnapshot();
+ expect(screen.getByText('********')).toBeInTheDocument();
});
});
diff --git a/packages/core/client/src/schema-component/antd/variable/__tests__/variable.test.tsx b/packages/core/client/src/schema-component/antd/variable/__tests__/variable.test.tsx
index acb1edda5..6fe181b02 100644
--- a/packages/core/client/src/schema-component/antd/variable/__tests__/variable.test.tsx
+++ b/packages/core/client/src/schema-component/antd/variable/__tests__/variable.test.tsx
@@ -13,14 +13,7 @@ describe('Variable', () => {
await userEvent.click(screen.getByText('x'));
await userEvent.click(screen.getByText('v1'));
await waitFor(() => {
- expect(screen.getByText('v1', { selector: '.ant-tag' })).toMatchInlineSnapshot(`
-
- v1
-
- `);
+ expect(screen.getByText('v1', { selector: '.ant-tag' }).innerHTML).toMatchInlineSnapshot('"v1"');
});
});
@@ -35,20 +28,7 @@ describe('Variable', () => {
await userEvent.click(variableSelector);
await userEvent.click(screen.getByText('v1'));
await waitFor(() => {
- expect(input).toMatchInlineSnapshot(`
-
-
- v1
-
-
- `);
+ expect(input.innerHTML).toMatchInlineSnapshot('"v1"');
});
});