具有使用已存根猫鼬模型的单元测试用例,我需要确保调用了authModel.create。如何断言呢?
我的单元测试:
const createUserStub = sinon.stub(authModel, 'create')
.resolves(userContent)
return request(app).post('/auth/create')
.send(userContent)
.set('Accept', 'application/json')
.expect((response) => {
const apiResponse = JSON.parse(response.text)
expect(createUserStub.calledOnce).to.equal(true)
expect(apiResponse).to.be.an('Object')
expect(apiResponse).to.have.property('_id')
expect(apiResponse).to.have.property('name')
expect(apiResponse).to.have.property('last_name')
expect(response.res.statusCode).to.equal(200)
}).end(done)
在第一个期望断言中始终返回false。
答案 0 :(得分:0)
您需要检查被调用的属性,而不是被调用的属性(namedOnce是sinon.spy的属性)。
expect(createUserStub.called).to.equal(true)
应该有效。谢谢!