a.test.js
it('添加 usermeta', async () => {
// 创建 ctx
const ctx = app.mockContext()
// 通过 ctx 访问到 service.test
const test = await ctx.service.test.insert()
assert(test)
})
service/a.js
async insert() {
console.log('test', this.app.mysql.insert) // undefined
const result = await this.app.mysql.insert('table', {test:1})
return result.affectedRows === 1
}
error
TypeError: this.app.mysql.insert is not a function
如果在controller中是可以成功使用它的,但在test的情况下,mysql方法下没有insert
unittest 环境中的数据库配置应该写到 config.default.js 中去。