Question

I'm using Karma to run an e2e test in AngularJS.

Within a describe() block, why are it() blocks always executed after any nested describe() blocks regardless of their order in the test?

For example:

describe( 'Hello Page Nav Bar', function()
{
    it( 'should be on the hello page', function()
    {
        expect( browser().location().url() ).toBe( '/hello' );
    } );

    // ... many other it() blocks relating to 'Nav Bar' ...

    // Create nested describe specifically for menu items within the nav bar
    describe( 'Nav Bar Menu Items', function()
    {
        it( 'should have 12', function()
        {
            expect( element( '.menu-items div' ).count() ).toBe( 12 );
        } );

        // ... many other it() blocks relating to 'Nav Bar Menu Items' ...
    } );
});

Will end up executing in this order:

* Hello Page Nav Bar
   *  Nav Bar Menu Items
      *   should have 12
   * should be on the hello page

It would make sense that I'd want to test "should be on the hello page" before anything else.

Was it helpful?

Solution

I agree.

A workaround is to always keep the describe block containing only other "describe blocks" or only "it blocks". This way, the order is kept coherent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top