简体   繁体   中英

Ordering of Angular e2e describe and it blocks

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM