import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { elementTree } from './utils/nativeMethod'; import { setupPage, snapshotInstanceManager, backgroundSnapshotInstanceManager } from '../../src/snapshot'; import { ComponentFromReactRuntime, wrapWithLynxComponent } from '../../src/core/compat/lynxComponent'; import { setupDocument } from '../../src/document'; import { Fragment, render } from 'preact'; import { globalEnvManager } from './utils/envManager'; const HOLE = null; let scratch; beforeAll(() => { globalEnvManager.switchToMainThread(); setupDocument(); setupPage(__CreatePage('0', 0)); }); beforeEach(() => { backgroundSnapshotInstanceManager.clear(); backgroundSnapshotInstanceManager.nextId = 0; snapshotInstanceManager.clear(); snapshotInstanceManager.nextId = 0; scratch = document.createElement('root'); }); afterEach(() => { render(null, scratch); elementTree.clear(); }); describe('addComponentElement', () => { it('should render a fake component element \'view\'', () => { class C extends ComponentFromReactRuntime { render() { return ; } } const jsx = wrapWithLynxComponent(__c => {__c}, ); scratch.ensureElements(); render(jsx, scratch); expect(scratch.__element_root).toMatchInlineSnapshot(` `); }); let snapshot = __c => ( {__c} ); it('should render a fake component element \'view\' - with some component attr', () => { class C extends ComponentFromReactRuntime { render() { return ; } } const jsx = wrapWithLynxComponent(snapshot, ); scratch.ensureElements(); render(jsx, scratch); expect(scratch.__element_root).toMatchInlineSnapshot(` `); }); let snapshotSpread = (__c, __spread) => {__c}; it('should render a fake component element \'view\' - with some component attr and spread', () => { class C extends ComponentFromReactRuntime { render() { return ; } } const jsx = wrapWithLynxComponent( snapshotSpread, , ); scratch.ensureElements(); render(jsx, scratch); expect(scratch.__element_root).toMatchInlineSnapshot(` `); }); it('should not render a fake component element \'view\' when component is not from legacy-react-runtime', () => { const jsx = wrapWithLynxComponent(snapshot, ); scratch.ensureElements(); render(jsx, scratch); expect(scratch.__element_root).toMatchInlineSnapshot(` `); }); it('should not render a fake component element \'view\' when there is removeComponentElement={true}', () => { class C extends ComponentFromReactRuntime { render() { return ; } } const jsx = wrapWithLynxComponent( snapshotSpread, , ); scratch.ensureElements(); render(jsx, scratch); expect(scratch.__element_root).toMatchInlineSnapshot(` `); }); it('should render a fake component element \'view\' when there is removeComponentElement={false}', () => { class C extends ComponentFromReactRuntime { render() { return ; } } const jsx = wrapWithLynxComponent( snapshotSpread, , ); scratch.ensureElements(); render(jsx, scratch); expect(scratch.__element_root).toMatchInlineSnapshot(` `); }); });