Created
May 12, 2021 08:21
-
-
Save Lxxyx/10875acdc02dcd30acf9f878cc1dc693 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { app } from '@midwayjs/hooks-testing-library' | |
// 自定义 Conext | |
/** | |
* 需求 | |
* 1. 匿名 Context(与请求无关) | |
* 2. 在函数运行时,支持自定义 Context | |
* | |
* 参考 | |
* 1. AsyncLocalStorage 在多个叠加情况的处理 | |
* 2. AsyncLocalStorage 的 Api 设计 | |
* | |
* 限制 | |
* 1. 匿名的上下文与函数的具名上下文不应该同时出现 | |
* 1.1 匿名上下文中调用函数应该报错 | |
*/ | |
import { api } from '@/apis' | |
const ctx = { | |
user: { | |
work_id: 1234567, | |
nick: 'fy' | |
} | |
} | |
app.enterWith(ctx) | |
await app.run(async () => { | |
const instance = await useInject('') | |
expect(instance.getWorkId()).toEqual(1234567) | |
}) | |
app.enterWith({ | |
user: { | |
work_id: 'for test' | |
} | |
}) | |
const result = await app.runFunction(api) | |
const response = await app.request(api) | |
expect(result.work_id === response.body.work_id === 'for test').toBeTruthy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment