Is there something like a jasmine `toNotContain` acceptance criteria for tests?

12,260

Solution 1

According to the documentation, you can use not:

getJasmineRequireObj().not.toContain

This example is from here:

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

Matchers

Each matcher implements a boolean comparison between the actual value and the expected value. It is responsible for reporting to Jasmine if the expectation is true or false. Jasmine will then pass or fail the spec.

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

Any matcher can evaluate to a negative assertion by chaining the call to expect with a not before calling the matcher.

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

Solution 2

Check below code which will be hwlpful, also documentation here 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");
});
Share:
12,260
Michael Czechowski
Author by

Michael Czechowski

Development · Consulting · Coaching javascript: window.atob('bWFpbEBkYWlseXNoLml0'); We design digital worlds of experience. » dailysh.it

Updated on June 02, 2022

Comments

  • Michael Czechowski
    Michael Czechowski about 2 years

    Jasmin comes with many functions for checking the expected values for validating specifications and tests.

    Is there besides

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

    somthing like a

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

    ?

    If not, how to add an extension or plugin to deliver this feature also to our community of developers?