0

Is it ok to have a nested describe for the purpose of read ability? Example:

describe('Atlas Search ', () => {
    beforeEach(() => browser.pause(20));

    before(()=> {
      searchPage.home();
      searchPage.searchBtn.click();
    });

    describe('When searching for items', () => {
      before(() => searchPage.searchBox.setValue('Darth'));

      it('should give 2 drop down hints', () => {
        browser.pause(800);

        [
          'Star Wars - Darth Vader',
          'Star Wars - Darth Maul',
        ].forEach((assertion, i) => {
          const el = searchPage.searchHints[i+1];
          const elText = searchPage.getHintText(el);
          elText.should.equal(assertion);
        });
      });

    });
})
[chrome  linux #0-0] Atlas Search
[chrome  linux #0-0]     When searching for items
[chrome  linux #0-0]        ✓ should give 2 drop down hints
[chrome  linux #0-0]
[chrome  linux #0-0] 1 passing (5.2s)

1 Answer 1

2

The purpose of describe is to allow BDD format:

describe('Given user logins', () => {
    describe('Given user Selects payment', () => {
        describe('Given user clicks pay', () => {
            it('Then deducts payment', () => {   

            })    
        })
    })
})

So it's perfectly fine to nest the describe. You can write steps in each describe block using beforeEach

describe('Given user logins', () => {

    beforeEach(async function() {
         login();
    });

    describe('Given user Selects payment', () => {

        beforeEach(async function() {
            selectpayment();
        });

        describe('Given user clicks pay', () => {
            it('Then deducts payment', () => {  

            })    
        })
    })
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.