【问题标题】:Is there something like a jasmine `toNotContain` acceptance criteria for tests?是否有类似 jasmine `toNotContain` 的测试验收标准?
【发布时间】:2016-09-25 19:09:54
【问题描述】:

Jasmin 带有许多用于检查预期值以验证规范和测试的功能。

还有没有

getJasmineRequireObj().toContain = function() { ... };

有点像

getJasmineRequireObj().toNotContain = function() { ... };

?

如果没有,如何添加扩展或插件来提供此功能 加入我们的开发者社区?

【问题讨论】:

    标签: javascript unit-testing testing jasmine karma-runner


    【解决方案1】:

    根据文档,可以使用not

    getJasmineRequireObj().not.toContain
    

    这个例子来自here:

    describe("The 'toBe' matcher compares with ===", function() {
    

    匹配器

    每个匹配器都在实际值和期望值之间进行布尔比较。它负责向 Jasmine 报告预期是真是假。然后 Jasmine 将通过或不通过规范。

        it("and has a positive case", function() {
            expect(true).toBe(true);
        });
    

    任何匹配器都可以通过在调用匹配器之前将expect 的调用与not 链接起来来评估否定断言。

        it("and can have a negative case", function() {
            expect(false).not.toBe(true);
        });
    });
    

    【讨论】:

      【解决方案2】:

      检查下面的代码,这将是 hwlpful,还有文档 这里https://jasmine.github.io/2.0/introduction.html

      it("also works for finding a substring", function() {
        var a = "foo bar baz";
      
        expect(a).toContain("bar");
        expect(a).not.toContain("quux");
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-12
        • 1970-01-01
        • 2012-06-27
        • 2014-03-27
        • 2020-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多