From 02c598d8585547b381718f82c3e53c36aabadb94 Mon Sep 17 00:00:00 2001
From: * <8>
Date: Thu, 14 Jul 2022 14:51:51 +0800
Subject: [PATCH] Match-id-ea7fb2cf4b62d8a3051ace4f27a15d66601524a4
---
.../ComponentTest/ForwardRef.test.js | 45 +++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 scripts/__tests__/ComponentTest/ForwardRef.test.js
diff --git a/scripts/__tests__/ComponentTest/ForwardRef.test.js b/scripts/__tests__/ComponentTest/ForwardRef.test.js
new file mode 100644
index 00000000..993d800a
--- /dev/null
+++ b/scripts/__tests__/ComponentTest/ForwardRef.test.js
@@ -0,0 +1,45 @@
+import * as Horizon from '@cloudsop/horizon/index.ts';
+import { getLogUtils } from '../jest/testUtils';
+
+describe('ForwardRef', () => {
+ const LogUtils = getLogUtils();
+ it('ForwardRef包裹的函数组件应该正常触发effect', () => {
+ function App(props, ref) {
+ Horizon.useEffect(() => {
+ LogUtils.log('effect');
+ return () => {
+ LogUtils.log('effect remove');
+ };
+ });
+ return ;
+ }
+
+ const Wrapper = Horizon.forwardRef(App);
+
+ Horizon.act(() => {
+ Horizon.render(, container);
+ });
+ expect(LogUtils.getAndClear()).toEqual(['effect']);
+ Horizon.act(() => {
+ Horizon.render(, container);
+ });
+ expect(LogUtils.getAndClear()).toEqual(['effect remove', 'effect']);
+ });
+
+ it('memo组件包裹的类组件', () => {
+ class Component extends Horizon.Component {
+ render() {
+ return ;
+ }
+ }
+
+ const Wrapper = Horizon.memo(Component);
+
+ Horizon.act(() => {
+ Horizon.render(, container);
+ });
+ Horizon.act(() => {
+ Horizon.render(, container);
+ });
+ });
+});