typescript - chai 无法比较类类型
问题描述
我正在使用 chai 来比较 SimpleModel 类型的返回值是否属于 SimpleModel 类型。尽管我的 IDE 确认类型匹配,但它给了我这个错误:
AssertionError: expected {} to be a simplemodel
这是我的简单设置:
export class SimpleModel {
public test_property: string;
}
然后我像这样在我的测试中使用它:
it('(Simple Value)"', () => {
const simpleModel: SimpleModel = new SimpleModel();
expect(simpleModel).to.be.a('SimpleModel'); //ERROR HAPPENS HERE
});
再次 simpleModel 是,我的 IDE 确认了这一点,类型为SimpleModel
. 我不确定为什么 Chai 也会在错误中转换('SimpleModel')
为。'simplemodel'
解决方案
a
测试typeof
or [Symbol.toStringTag]
。您必须使用instanceof
.
推荐阅读
- vba - 如果单价格式设置为货币,则计算文本框不会计算
- scrapy - 为什么 xpath text() 节点不能嵌套在 Scrapy 中
- php - Wordpress:推进自定义字段多选
- python - 如何使用 tensorflow 的 tf.data.Dataset API 预处理数据?
- php - 在页面上显示来自数据库的照片的问题
- javascript - ReactDOM.render 渲染页面
- web-scraping - 为什么 YouTube 在浏览器中返回的结果与原始 HTTP 请求不同?
- c++ - C++20:多种类型的概念及其约束,正确的语法?
- x86 - intel i7-8705G使用什么指令集?
- sql-server - 通过 VB6 和 ADO 插入多个参数