【发布时间】:2017-03-21 13:43:55
【问题描述】:
我很好奇如何将value 测试为string 或 number 和chai。当这是一个严格的测试时,我知道如何为string 或number 编写测试。但是,当value 可能是其中之一时,如何处理呢?
对字符串的测试:
describe("test", () => {
it("should be a string", () => {
let value = "1234";
value.should.be.a("string");
});
});
一个数字的测试:
describe("test", () => {
it("should be a number", () => {
let value = 1234;
value.should.be.a("number");
});
});
是否有 chai 的内置方式来执行此操作?
我知道我可以做一些变通方法,如下所示。但这感觉有点hacky。
describe("test", () => {
it("should be a number or string", () => {
let value = 1234;
(typeof value).should.be.oneOf(["string", "number"]);
});
});
【问题讨论】:
标签: javascript unit-testing mocha.js chai