- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 JavaScript 和测试的新手。直到最近,我才写了人生中的第一次测试。我指的是“Chai.js”文档,它说:
The assert style is very similar to node.js' included assert module, with a bit of extra sugar. Of the three style options, assert is the only one that is not chainable. Check out the Style Guide for a comparison.
The BDD styles are expect and should. Both use the same chainable language to construct assertions, but they differ in the way an assertion is initially constructed. Check out the Style Guide for a comparison.
“构造断言的可链接语言”是什么意思?这是一个 example我写的测试文件。
谢谢!
最佳答案
chai
中的 expect/should 断言可以在看起来像单个语句的情况下相互链接。在以下示例中,首先对对象执行断言,然后对对象的属性执行断言,该对象成为第一个断言之后的链接上下文:
expect({ foo: 'baz' }).to.have.property('foo')
.and.not.equal('bar');
如果你想对断言做同样的事情,你必须在两个不同的断言中完成它,一个将在对象上执行,另一个在对象的属性上执行:
var foo = { foo: 'baz' };
assert.property(foo, "foo", "object does not contain a foo property");
assert.notEqual(foo.foo, "bar", "The foo property is equal to 'bar'");
关于javascript - 测试环境中的 "chainable"(mocha、chai)是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30023175/
我正在寻找匹配以下内容的最佳方法: expect([ { C1: 'xxx', C0: 'this causes it not to match.' }
我该如何做 or使用 chai.should 进行测试? 例如就像是 total.should.equal(4).or.equal(5) 或者 total.should.equal.any(4,5)
我正在使用带有 chai 断言库的 webdriverio 进行 UI 测试,同时断言一个字符串我想知道我是否可以让 chai 在断言通过或失败时根据步骤返回 true/false。 var text
我正在使用 Nightwatch JS v0.9.16运行 Selenium /chai在我的本地主机上测试。所有断言都适用于 nightwatch,但我无法让 chai 断言在记者中显示。 此问题已
我正在尝试在 typescript 中使用 chai,但我无法让任何断言按预期工作。 包.json "dependencies": { "@types/chai": "^4.0.1", "@t
我一直在尝试创建自己的自定义 chai 断言(基于 Cypress 配方模板:https://github.com/cypress-io/cypress-example-recipes/blob/ma
我最近从 should.js 切换到 chai.js,因为我发现前者在基于浏览器的测试中造成障碍。由于支持语法,因此更改不需要对我的测试套件进行任何更改,但我看到失败测试的输出不再以有用的方式向我显示
我即将让我们的测试与 Karma 一起运行,但我错过了最后一步(我认为),得到 chai-jquery为了表现,我尝试了两个不同的插件 https://www.npmjs.com/package/ka
使用 Protractor 时,chai 和 mocha 框架中 promise 的 chai 有什么区别? 最佳答案 Chai - 测试断言库,允许您使用 expect、should 等关键字测试代
我想编写一个 NodeJS chai 测试,它检查某些服务调用的结果(这是一个数组)是否包含一个与我期望的对象相同的对象。结果中可能还有一些我不想检查的字段。 有两个 chai 插件可以解决这个问题:
在我的 Chai 测试中,我经常发现自己想要使用他们的断言,例如 .to.be.empty、.to.be.true 等,因为我发现它们比 .to.be.length(1) 或 .to.be.equal
在我的 Chai 测试中,我经常发现自己想要使用他们的断言,例如 .to.be.empty、.to.be.true 等,因为我发现它们比 .to.be.length(1) 或 .to.be.equal
下面的调用 filestore.getBlockNumber.q(fileHash).should.eventually.bignumber.equal(blockNumber) 失败 Asserti
制作我的第一个 Express 应用程序时,我正在尝试为 api 端点编写测试,并使用数据结构作为数据库的占位符,但即使测试“通过”,控制台中仍会出现错误,如图所示' import chai fr
我有以下功能要测试: // ... const local = new WeakMap(); export default class User { // ... async password
我正在尝试为我的API生成 Istanbul 尔代码覆盖率。我已经研究了SO中的许多答案以及 Istanbul 尔的文档,但没有任何对我有用。 Mocha 测试运行良好,一切都通过了,甚至 Istan
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
我有一个字符串数组['abc,'def','ghi','jkl'] 我的字符串 B 等于 'j'。 我想用 chai 检查数组中的任何元素是否有字符串 B 作为子字符串 这可能吗?我似乎无法弄清楚如何
使用Chai,如何查看元素For example, a div with the class .avatar存在? 我试过 to.exist但它不起作用。 最佳答案 exist vanilla Cha
是否可以使用 chai 断言数组包含多个特定项? 例如,我希望这可以工作: ['foo', 'bar'].should.include(['foo', 'bar']) 相反 chai 抛出:“预期 [
我是一名优秀的程序员,十分优秀!