Angular e2e的排序和它的block

Ordering of Angular e2e describe and it blocks

本文关键字:block 排序 e2e Angular      更新时间:2023-09-26

我使用Karma在AngularJS中运行一个端到端测试。

describe()块中,为什么it()块总是在任何嵌套的describe()块之后执行,而不管它们在测试中的顺序如何?例如:

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' ...
    } );
});

将以以下顺序执行:

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

我想测试"should be on the hello page"在其他任何东西之前

是有意义的。
我同意。

一个解决方法是始终保持描述块只包含其他"描述块"或只包含"它块"。这样,顺序是一致的。