【发布时间】:2019-08-29 11:02:49
【问题描述】:
我正在尝试向我正在开发的节点应用程序添加一些测试。我浏览了手动模拟的笑话文档,并尝试按照指示创建 mocks 文件夹。请在下面找到文件夹结构。
app
- firebase
- fb.js
- __mocks__
- fb.js
- firebase-admin.js
- resolvers
- mutation.js
__tests__
- user.spec.js
如您所见,我尝试模拟两个模块,fb.js(用户模块)和 firebase-admin.js(node_modules 模块)。 firebase-admin.js 模拟工作没有任何问题。但是用户模块模拟甚至没有被开玩笑所接受。实际的 fb.js 模块一直在被调用。
我尝试为我的项目中的各种用户模块创建 mocks 目录,但没有一个被选中。有没有我遗漏的额外配置???。目前我正在通过仅模拟 firebase-admin 节点模块来解决这个问题。但我想模拟用户模块而不是 firebase-admin 模块,以便我的 firebase 配置也被模拟。如果需要更多信息,请告诉我。
__mocks__/fb.js
module.exports = {
auth: jest.fn(() => "testing")
};
__mocks__/fb-admin.js
module.exports = {};
__tests__/user.spec.js
const request = require('supertest');
const server = require('../app').createHttpServer({});
const app = request(server);
describe('login resolvers', () => {
test('should sign up user', async () => {
const response = await app.post('/')
.send({
query: `mutation {
signUp(idToken: "esd45sdfd...") {
user {
id
locked
revoked
}
}
}
`,
})
.set('Accept', 'application/json')
.expect(200);
console.log(response.text);
});
});
app/resolvers/mutation.js
const admin = require('../firebase/fb');
/* other app code here */
【问题讨论】:
标签: javascript node.js jes