尽管可以通过表访问CLI,但在运行测试时获取表未定义

问题描述

为什么测试会说表未定义?

这是运行npm run test时得到的:

knex:query select * from "users" undefined +0ms
GET /api/users 200 28.804 ms - 2
     ✓ returns 200 and [] (55ms)

1 passing (216ms)

在.env文件中,我有这行调试knex:

DEBUG=knex:query

在测试文件中,我正在运行它:


context('when the there are no users',() => {
            it('returns 200 and []',() => {
                console.log(db,"hi")
                return supertest(app)
                    .get('/api/users')
                    .set({ "Authorization": `Bearer ${process.env.API_TOKEN}` })
                    .expect(200,[])
            })
        })

这是服务方法

   getAllUsers(knex) {
        return knex.select('*').from('users')
    },

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)