From 1abff78de214699da3f1cbcd8a2fe210a18a1b8a Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 25 Jul 2023 00:22:20 +0200 Subject: [PATCH] fix(ct): remove json typechecking (#24114) --- packages/playwright-ct-core/src/mount.ts | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/packages/playwright-ct-core/src/mount.ts b/packages/playwright-ct-core/src/mount.ts index fbdc133fff..a671368104 100644 --- a/packages/playwright-ct-core/src/mount.ts +++ b/packages/playwright-ct-core/src/mount.ts @@ -52,8 +52,6 @@ export const fixtures: Fixtures< mount: async ({ page }, use) => { await use(async (component: JsxComponent | string, options?: MountOptions) => { - if (options?.props && !isJson(options.props)) - throw new Error('The mount function props are not JSON serializable.'); const selector = await (page as any)._wrapApiCall(async () => { return await innerMount(page, component, options); }, true); @@ -68,8 +66,6 @@ export const fixtures: Fixtures< update: async (options: JsxComponent | Omit) => { if (isJsxApi(options)) return await innerUpdate(page, options); - if (options?.props && !isJson(options.props)) - throw new Error('The update function props are not JSON serializable.'); await innerUpdate(page, component, options); } }); @@ -78,24 +74,6 @@ export const fixtures: Fixtures< }, }; -const jsonType: Record = { - string: (value: any) => typeof value === 'string', - number: (value: any) => typeof value === 'number', - boolean: (value: any) => typeof value === 'boolean', - null: (value: any) => value === null, - array: (value: any) => Array.isArray(value) && value.every(isJson), - object: (value: any) => typeof value === 'object' && value !== null && !Array.isArray(value) - && Object.values(value).every(isJson), -}; - -function isJson(value: any): boolean { - const valueType = Array.isArray(value) ? 'array' : typeof value; - const validate = jsonType[valueType]; - if (validate) - return validate(value); - return false; -} - function isJsxApi(options: Record): options is JsxComponent { return options?.kind === 'jsx'; }