test(remesh-react): 添加关于 fromEvent, fromQuery 回收机制的测试用例 #94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这里添加了三个关于 fromEvent, fromQuery 回收机制的测试用例。基本的检测方式是在 2.6s 时触发 command 将
<Additional id={...}>
删除,然后检测 effect 内的测试函数被调用的次数。remesh-react-query-basic.test.tsx
是基本的测试用例,两次触发然后等待 2.6s 之后再执行删除<Additional>
后,effect 都能被正确中断,测试函数都只被调用 3 次(加载时立即触发的一次和之后每秒钟触发的一次),最终得到的是仅 6 次调用。remesh-react-query.test.tsx
和remesh-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,还是仅由自己内部定义,都能正确被中断和回收。