首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取无效的Chai属性:'calledWith‘

获取无效的Chai属性:'calledWith‘
EN

Stack Overflow用户
提问于 2019-02-07 21:52:07
回答 1查看 2K关注 0票数 2

我正在为我的express应用程序设置单元测试。当我运行我的测试时,它失败了,并显示以下错误

代码语言:javascript
复制
import * as timestamp from './timestamp'
import chai, { expect } from 'chai'
import sinonChai from 'sinon-chai'
import { mockReq, mockRes } from 'sinon-express-mock'
//chai.use(sinonChai); <-- `I removed this because it was creating this error:: TypeError: Cannot read property 'use' of undefined`


describe('hello world', () => {

    it('should behave...', () => {
        const request = {
            body: {
              foo: 'bar',
            },
          }
          const req = mockReq(request)
          const res = mockRes()

          timestamp.timestamp(req, res)


          expect(res.json).to.have.been.calledWith({})

    });
});
EN

回答 1

Stack Overflow用户

发布于 2019-02-09 01:03:32

我想是你的模块系统还是捆绑器(webpack?)弄得一团糟。这在我的示例中工作得很好:https://runkit.com/fatso83/chai-spy-example

前几天我在WebKit上看到了这一点,我通过将导入拆分成两行来修复它。尝试替换

代码语言:javascript
复制
import chai, { expect } from 'chai';

使用

代码语言:javascript
复制
import chai, from 'chai';
import { expect } from 'chai';
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54574912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档