eggjs / eggjs/egg

jest单元测试获取不到ctx上的service

Open
#4,701 6 comments 0 reactions 0 assignees View on GitHub
Inactive
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

## What happens?
jest写单元测试 `egg-mock/bootstrap`里面的ctx获取不到service

## 最小可复现仓库
```
import { Context } from 'egg';
import { app } from 'egg-mock/bootstrap';

describe('common tset', () => {
it('get list', async () => {
let ctx: Context = app.mockContext();
console.log(ctx.service.test) // undefined
})
})
```

## 复现步骤,错误日志以及相关配置

let ctx: Context = app.mockContext();
console.log(ctx.service.test) // undefined
获取不到srvice等信息,有什么办法解决吗?

## 相关环境信息
- **操作系统**:MacOS
- **Node 版本**:10.24
- **Egg 版本**:2.6.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.