如何检查toBe方法中的不同值

时间:2014-06-14 04:25:50

标签: javascript selenium-webdriver jasmine

我正在编写一个测试来检查所有链接是否都有正确的文本。 但我需要检查两个值,它可以是“启用”或“禁用”

expect(toggleName).toBe('Disable'); 

如何检查2个或更多值。

1 个答案:

答案 0 :(得分:0)

您可以撰写custom matcher

您可以在jsfiddle中找到以下示例:

describe('Custom matcher', function () {
    var customMatchers = {
        toBeThisOrThat: function (util, customEqualityTesters) {
            return {
                compare: function (actual) {
                    var result = {};
                    result.pass = util.equals(actual, "This", customEqualityTesters) || util.equals(actual, "That", customEqualityTesters);
                    if (result.pass) {
                        result.message = "Expected " + actual + " not to be this or that";
                    } else {
                        result.message = "Expected " + actual + " to be this or that";
                    }
                    return result;
                }
            };
        }
    };
    beforeEach(function () {
        jasmine.addMatchers(customMatchers);
    });

    it("should equal this or that", function () {
        expect('This').toBeThisOrThat();
        expect('That').toBeThisOrThat();
        expect('foo').not.toBeThisOrThat();
    });
})