Skipping tests

In a similar fashion to forcing tests, tests can be skipped using xit instead of it, and xdescribe instead of describe. This means that the tests will not be run as part of your suite. While there are legitimate reasons to skip tests in a production system, these reasons should always be an extreme circumstance, and should always be very short-lived.

We can skip a test in two ways. The first is by marking the test with an x, so instead of using it, use xit. The second way of skipping a test is by calling the pending function, as follows:

describe("skipped test examples", () => { 
    xit("skipped test with no reason", () => { 
        expect(false).toBeTruthy(); 
    }); 
    it("", () => { 
        expect(false).toBeTruthy(); 
        pending("this test should be implemented correctly"); 
    }) 
}); 

Here, we have two tests. The first test is skipped by using xit, and the second test is skipped due to a call to the pending function. Note that the call to the pending function is actually after the expectation. If we look closely at the expectation, we can see that this test should fail, as we are expecting false toBeTruthy. What this means is that the call to the pending function can occur anywhere within the test itself, and when Jasmine finds a call to pending, it will skip the entire test.

There is a subtle and important difference between the use of xit and the use of the pending function. The pending function allows us to give a reason for the skipping of the test. If we run this test, we will see the output as follows:

Here, we can see that two tests were skipped. The first test shows the "Temporarily disabled with xit" message, where the second test shows the message that we specified in the call to the pending function, which was "this test should be implemented correctly". This makes it very clear to anyone in our team why this test was skipped. It acts as a signal that the test should be re-enabled when the reason for skipping it is no longer valid.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.134