diff --git a/packages/react-native-fantom/src/__tests__/Fantom-itest.js b/packages/react-native-fantom/src/__tests__/Fantom-itest.js index f16d30bd10fbee..250c31d4d828fc 100644 --- a/packages/react-native-fantom/src/__tests__/Fantom-itest.js +++ b/packages/react-native-fantom/src/__tests__/Fantom-itest.js @@ -76,28 +76,30 @@ describe('Fantom', () => { // TODO: when error handling is fixed, this should verify using `toThrow` it('should throw when running a task inside another task', () => { - let lastCallbackExecuted = 0; + let threw = false; + runTask(() => { - lastCallbackExecuted = 1; - runTask(() => { - lastCallbackExecuted = 2; - throw new Error('Recursive runTask should be unreachable'); - }); + // TODO replace with expect(() => { ... }).toThrow() when error handling is fixed + try { + runTask(() => {}); + } catch { + threw = true; + } }); - expect(lastCallbackExecuted).toBe(1); + expect(threw).toBe(true); + + threw = false; runTask(() => { queueMicrotask(() => { - lastCallbackExecuted = 3; - runTask(() => { - lastCallbackExecuted = 4; - throw new Error( - 'Recursive runTask from micro-task should be unreachable', - ); - }); + try { + runTask(() => {}); + } catch { + threw = true; + } }); }); - expect(lastCallbackExecuted).toBe(3); + expect(threw).toBe(true); }); }); @@ -125,16 +127,24 @@ describe('Fantom', () => { runTask(() => { root.render( <> - - + + , ); }); expect(root.getRenderedOutput().toJSX()).toEqual( <> - - + + , ); @@ -233,18 +243,26 @@ describe('Fantom', () => { runTask(() => { root.render( <> - - hello world! - + + hello world! + , ); }); expect(root.getRenderedOutput({props: []}).toJSX()).toEqual( <> - - hello world! - + + hello world! + , ); diff --git a/packages/react-native-fantom/src/getFantomRenderedOutput.js b/packages/react-native-fantom/src/getFantomRenderedOutput.js index 45500fde1742a0..73840c844651e2 100644 --- a/packages/react-native-fantom/src/getFantomRenderedOutput.js +++ b/packages/react-native-fantom/src/getFantomRenderedOutput.js @@ -152,16 +152,20 @@ function convertRawJsonToJSX( function createJSXElementForTestComparison( type: string, props: mixed, + key?: ?string, ): React.Node { const Tag = type; - return ; + return ; } function rnTypeToTestType(type: string): string { return `rn-${type.substring(0, 1).toLowerCase() + type.substring(1)}`; } -function jsonChildToJSXChild(jsonChild: FantomJsonObject | string): React.Node { +function jsonChildToJSXChild( + jsonChild: FantomJsonObject | string, + index?: ?number, +): React.Node { if (typeof jsonChild === 'string') { return jsonChild; } else { @@ -172,6 +176,7 @@ function jsonChildToJSXChild(jsonChild: FantomJsonObject | string): React.Node { jsxChildren == null ? jsonChild.props : {...jsonChild.props, children: jsxChildren}, + index != null ? String(index) : undefined, ); } } @@ -184,7 +189,7 @@ function jsonChildrenToJSXChildren(jsonChildren: FantomJsonObject['children']) { let allJSXChildrenAreStrings = true; let jsxChildrenString = ''; for (let i = 0; i < jsonChildren.length; i++) { - const jsxChild = jsonChildToJSXChild(jsonChildren[i]); + const jsxChild = jsonChildToJSXChild(jsonChildren[i], i); jsxChildren.push(jsxChild); if (allJSXChildrenAreStrings) { if (typeof jsxChild === 'string') { diff --git a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js index a7ea8e84e8dd96..8ad459de8af147 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js @@ -487,7 +487,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -549,7 +548,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -610,7 +608,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -942,7 +939,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -1003,7 +999,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -1314,13 +1309,9 @@ describe('IntersectionObserver', () => { }); expect(node.isConnected).toBe(false); - Fantom.runTask(() => { - observer = new IntersectionObserver(() => {}); - observer.observe(node); - // TODO what happens if this throws an exception? - observer.unobserve(node); - throw new Error('unobserve should not throw'); - }); + observer = new IntersectionObserver(() => {}); + observer.observe(node); + observer.unobserve(node); }); it('should not report the initial state if the target is unobserved before it is delivered', () => { @@ -1497,19 +1488,16 @@ describe('IntersectionObserver', () => { const node = ensureReactNativeElement(maybeNode); - Fantom.runTask(() => { - observer1 = new IntersectionObserver(() => {}); - observer2 = new IntersectionObserver(() => {}); + observer1 = new IntersectionObserver(() => {}); + observer2 = new IntersectionObserver(() => {}); - observer1.observe(node); - observer2.observe(node); + observer1.observe(node); + observer2.observe(node); - observer1.unobserve(node); + observer1.unobserve(node); - // The second call shouldn't log errors (that would make the test fail). - observer2.unobserve(node); - throw new Error('unobserve should not throw'); - }); + // The second call shouldn't log errors (that would make the test fail). + observer2.unobserve(node); }); }); diff --git a/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js b/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js index 25801da127c9c2..8163f88a15a57b 100644 --- a/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js +++ b/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js @@ -383,14 +383,14 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }}> , ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); const observerCallback = jest.fn(); const observer = new MutationObserver(observerCallback); @@ -968,13 +968,13 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }} />, ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); const observerCallback = jest.fn(); const observer = new MutationObserver(observerCallback); @@ -1016,13 +1016,13 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }} />, ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); const observerCallback = jest.fn(); const observer = new MutationObserver(observerCallback); @@ -1048,13 +1048,13 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }} />, ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); Fantom.runTask(() => { root.render(<>);