From 82933f482d8ae1faea81c00302780040d57b60e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Thu, 28 Aug 2025 09:00:55 +0200 Subject: [PATCH] chore: fix nightly test by excluding RCTSwitch style from snapshot --- src/__tests__/react-native-api.test.tsx | 14 +++++------ src/test-utils/json.ts | 32 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/test-utils/json.ts diff --git a/src/__tests__/react-native-api.test.tsx b/src/__tests__/react-native-api.test.tsx index 9c4ed53b..1c0d84b1 100644 --- a/src/__tests__/react-native-api.test.tsx +++ b/src/__tests__/react-native-api.test.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { FlatList, Image, Modal, ScrollView, Switch, Text, TextInput, View } from 'react-native'; import { render, screen } from '..'; +import { mapJsonProps } from '../test-utils/json'; const isReact19 = React.version.startsWith('19.'); const testGateReact19 = isReact19 ? test : test.skip; @@ -109,18 +110,17 @@ test('React Native API assumption: with nested Text renders single h test('React Native API assumption: renders a single host element', () => { render(); - expect(screen.toJSON()).toMatchInlineSnapshot(` + expect( + mapJsonProps(screen.toJSON(), { + style: '/* Intentional excluded */', + }), + ).toMatchInlineSnapshot(` diff --git a/src/test-utils/json.ts b/src/test-utils/json.ts new file mode 100644 index 00000000..62ec057e --- /dev/null +++ b/src/test-utils/json.ts @@ -0,0 +1,32 @@ +import type { ReactTestRendererJSON } from 'react-test-renderer'; + +type JsonPropsMapper = { + [key: string]: unknown; +}; + +export function mapJsonProps( + element: T, + mapper: JsonPropsMapper, +): T { + if (Array.isArray(element)) { + return element.map((e) => mapJsonProps(e, mapper)) as T; + } + + if (!element) { + return element; + } + + const resultProps = { ...element.props }; + Object.keys(mapper).forEach((key) => { + if (key in element.props) { + resultProps[key] = mapper[key]; + } + }); + + const resultElement = { ...element, props: resultProps }; + Object.defineProperty(resultElement, '$$typeof', { + value: Symbol.for('react.test.json'), + }); + + return resultElement; +}