Testacular(现在是Karma)很棒,角度场景也是如此。然而,将它们结合使用证明是一项挑战。在Testacular中有一个ANGULAR-SCENARIO-ADAPTER,但它打破了简单的测试。如果你自己包含angular-scenario.js,那么Testacular根本就不会运行任何测试。有没有人能正常运行?
我试图通过一个简单的测试来使用它,但我看到了一些奇怪的行为:
测试:
describe('Simple', function(){
it('should compare strings', function(){
expect('foo').toBe('foo');
});
});
config的正常行为:
files = [
JASMINE,
JASMINE_ADAPTER,
// ANGULAR_SCENARIO,
// ANGULAR_SCENARIO_ADAPTER,
'tests/lib/angular/angular.js',
'tests/sample.js'
];
输出:
$ testacular start
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser ChromeCanary
info (Chrome 25.0): Connected on socket id KRwEUtKtiaJs3MoiEsNg
Chrome 25.0: Executed 1 of 1 SUCCESS (0.061 secs / 0.003 secs)
添加ANGULAR适配器配置时:
files = [
JASMINE,
JASMINE_ADAPTER,
ANGULAR_SCENARIO,
ANGULAR_SCENARIO_ADAPTER,
'tests/lib/angular/angular.js',
'tests/sample.js'
];
输出是:
$ testacular start
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser ChromeCanary
info (Chrome 25.0): Connected on socket id 5YZA2fSuNXjmI-yRFGF6
Chrome 25.0 Simple should compare strings FAILED
expect undefined toBe "foo"
/Users/iwein/projects/epec/spa/tests/sample.js:3:9: expected "foo" but was undefined
Chrome 25.0: Executed 1 of 1 (1 FAILED) (0.195 secs / 0.018 secs)
我也尝试过自己包含angular-scenario.js
,但那是一个死胡同。
//inside testacular.conf.js
files = [
JASMINE,
JASMINE_ADAPTER,
'tests/lib/angular/angular.js',
'tests/sample.js'
];
我得到输出:
$ testacular start
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser ChromeCanary
info (Chrome 24.0): Connected on socket id uEzVQ6tqSu7M7tak4F6v
Chrome 24.0 Array #indexOf() should return -1 when the value is not present FAILED
Expected true to be false.
Error: Expected true to be false.
at null.<anonymous> (/..../tests/sample.js:4:17)
Chrome 24.0: Executed 1 of 1 (1 FAILED) (0.07 secs / 0.004 secs)
如果我在混音中添加角度场景:
//inside testacular.conf.js
files = [
JASMINE,
JASMINE_ADAPTER,
'tests/lib/angular/angular.js',
'tests/lib/angular/angular-scenario.js',
'tests/sample.js'
];
测试根本不运行:
$ testacular start
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser ChromeCanary
info (Chrome 24.0): Connected on socket id GcyCTxuvhyFcCaE14BEP
Chrome 24.0: Executed 0 of 0 SUCCESS (0.116 secs / 0 secs)
有没有人让这个正常运行? true
成为undefined
后会怎样?
答案 0 :(得分:16)
你不能混合2合一的测试配置。你应该做的是准备2个不同的测试配置:一个用于运行单元测试,另一个用于运行e2e测试。
然后,你运行两次:首先执行单元测试,然后执行e2e测试。通常我非常非常频繁地运行单元测试(每次保存!),而e2e测试就在commmit之前(因为那些测试运行时间更长)。我们希望从单元测试中获得最快的反馈,而e2e测试提供最终的安全网,并确保单元测试(导航,UI等)难以覆盖的应用程序部分仍能正常工作。
这是AngularJS种子使用的技术,您可以在此处查看相应的定义:https://github.com/angular/angular-seed/tree/master/config
答案 1 :(得分:12)
true
成为undefined
的原因是您使用的是角度方案版本的expect
(不是Jasmine的版本),其中包含一个名为 future
<的参数/ em>将在页面加载后评估为页面元素或属性。
Angular-scenario希望 future
参数是具有value
属性的对象。因此,当您传入true
时,它会尝试访问评估为true.value
的{{1}}。
undefined
效果很好。