gpt4 book ai didi

javascript - 测试环境中的 "chainable"(mocha、chai)是什么意思?

转载 作者:行者123 更新时间:2023-11-29 21:49:08 26 4
gpt4 key购买 nike

我是 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com