我正在使用Karma在AngularJS中运行e2e测试。
在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
我想在其他任何事情之前测试“应该在hello页面上”是有意义的。
答案 0 :(得分:1)
我同意。
解决方法是始终保持describe块仅包含其他“describe blocks”或仅包含“it blocks”。这样,订单就保持连贯。