在 柴,你可以做以下的事情:
expect({}).to.exist;
exist
不是函数调用,但这仍然适用于测试框架。相反(expect({}).to.not.exist
)导致测试失败,但同样, exist
不是函数调用。
这些断言如何在不让我调用函数的情况下工作?事实上,如果我试着说 expect({}).to.exist()
测试失败,因为 exist
不是一个功能。
在 柴,你可以做以下的事情:
expect({}).to.exist;
exist
不是函数调用,但这仍然适用于测试框架。相反(expect({}).to.not.exist
)导致测试失败,但同样, exist
不是函数调用。
这些断言如何在不让我调用函数的情况下工作?事实上,如果我试着说 expect({}).to.exist()
测试失败,因为 exist
不是一个功能。
我想通了(至少,我想通了 一个 方法)。使用 JavaScript getter:
var throws = {
get a() {
throw new Error('a');
},
get b() {
throw new Error('b');
},
get c() {
throw new Error('c');
}
};
做的时候 throws.a
, throws.b
, 要么 throws.c
,将抛出相应的错误。
从那时起,构建Chai中包含的断言相当容易。
我想通了(至少,我想通了 一个 方法)。使用 JavaScript getter:
var throws = {
get a() {
throw new Error('a');
},
get b() {
throw new Error('b');
},
get c() {
throw new Error('c');
}
};
做的时候 throws.a
, throws.b
, 要么 throws.c
,将抛出相应的错误。
从那时起,构建Chai中包含的断言相当容易。