alecxe alecxe - 5 months ago 8x
Javascript Question

Simplifying multiple boolean checks into a single one

In one of our tests, we have the following set of expectations:


On one hand, having multiple simple expectations provide a more precise and understandable feedback, but, on another, this looks like it violates the DRY principle and the "one expectation per test" commonly acceptable guideline.

Is there a way to convert/simplify it to a single expect?

is a Page Object,
and other page object fields are navigation links.


I think you've misunderstood the purpose of the "one expectation per test" guideline. The point isn't to combine a bunch of expectations into a single expectation, it's to split up your expectations into separate tests.

To follow the spirit of that guideline, you would write your tests like this:

describe("The header page", function () {
    var headerPage;
    beforeEach(function () {
        //Common logic here

    it("displays the dashboard", function () {

    it("displays the queue", function () {

    it("displays the claimSearch", function () {


That's a fair bit more verbose than what you have; but that's why these are guidelines not rules. It's a tradeoff between how verbose you make your tests, versus how easy they are to debug later. ("The header page displays the dashboard: FAILED") is a very clear and specific test failure message, compared to getting the same failure message regardless of which expectation actually failed.

I definitely would not try to combine all of these lines into a single line. If you don't want to split it into a bunch of different test cases I would just leave it how it is.