我正在使用 Karma 在 AngularJS 中运行 e2e 测试。
在 describe()
block 中,为什么 it()
block 总是在任何嵌套的 describe()
block ,无论它们在测试中的顺序如何?
例如:
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 页面上”是有道理的。
最佳答案
我同意。
解决方法是始终保持描述 block 仅包含其他“描述 block ”或仅包含“it block ”。这样,顺序就保持一致。
关于javascript - Angular e2e 描述的排序和它的阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16860668/