Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(remesh-react): 添加关于 fromEvent, fromQuery 回收机制的测试用例 #94

Merged

Conversation

undoZen
Copy link
Contributor

@undoZen undoZen commented Apr 1, 2024

这里添加了三个关于 fromEvent, fromQuery 回收机制的测试用例。基本的检测方式是在 2.6s 时触发 command 将 <Additional id={...}> 删除,然后检测 effect 内的测试函数被调用的次数。

remesh-react-query-basic.test.tsx 是基本的测试用例,两次触发然后等待 2.6s 之后再执行删除 <Additional> 后,effect 都能被正确中断,测试函数都只被调用 3 次(加载时立即触发的一次和之后每秒钟触发的一次),最终得到的是仅 6 次调用。

remesh-react-query.test.tsxremesh-react-query-deps.test.tsx 都会在 <Page> 的外层有一个 <RemeshScope domains={[AdditionalDomain(1)]}>,因此第一次删除 <Page> 里的 <Additional id={1}> 时,effect 会继续保留运行,第二次删除的是 <Additional id={2}> 此时 AdditionalDomain(2) 已经没有被任何 react 组件所使用,期望的是 effect 会被中断执行。因此第一次删除组件后还会完整触发 effect 内的 6 次调用,而第二次中断后,effect 内的测试函数就不会再被调用了,最终得到的是 9 次调用。

这两个测试用例的区别在于,后者定义的 AdditionalDomain 依赖了 SendCodeDomain,使用的是从依赖的 domain 获取的 Event,而前者使用自己在内部定义的 SendEvent,因此说明,无论订阅的 event 是来自于外部依赖的 domain,还是仅由自己内部定义,都能正确被中断和回收。

@undoZen undoZen force-pushed the testcases-for-fromEven-fromQuery branch from 026cfda to a517333 Compare April 1, 2024 09:55
@Lucifier129 Lucifier129 merged commit 815dcd2 into remesh-js:main Apr 1, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants