小编Jac*_*sey的帖子

是否可以在Jasmine.Js中检查toEqual中的多个类型?

我是Jasmine的新手,遇到了我希望String或null的情况.我尝试做一个或在toEqual之内,但我看到一些奇怪的结果让我相信我会以错误的方式进行.这种情况的最佳方法是什么?

也许我只是在考虑我的测试错误.我是否应该放弃一个测试以测试这两种情况的想法?

describe("Jasmine", function () {

    //1
    it("should be able to handle any(String) || null within toEqual for string", function () {
        expect("aString").toEqual(jasmine.any(String) || null);
    });

    //2
    it("should be able to handle any(String) || null within toEqual for null", function () {
        expect(null).toEqual(jasmine.any(String) || null);
    });

    //3
    it("should be able to handle null || any(String) within toEqual for string", function () {
        expect("aString").toEqual(null || jasmine.any(String));
    });

    //4
    it("should be able to handle null || any(String) within toEqual for null", function …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine

6
推荐指数
1
解决办法
5433
查看次数

标签 统计

jasmine ×1

javascript ×1