[英]Jasmine and Karma: Cannot find variable runs
我是否需要一個插件/ lib來使用run()並使用Jasmine等待()? 我正在查看Jasmine wiki頁面上的異步測試: https : //github.com/pivotal/jasmine/wiki/Asynchronous-specs 。
他們沒有提到需要特殊的lib /插件,所以我假設runs()和wait()應該開箱即用。
我的代碼看起來像這樣(它包含在描述中):
it('test', function() {
runs(function() {
});
});
我得到: ReferenceError: runs is not defined
我的業力配置的相關部分是:
files: [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'src/*.js',
'test/*.spec.js'
],
frameworks: ['jasmine'],
browsers: ['PhantomJS'],
plugins: [
'karma-spec-reporter',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-phantomjs-launcher'
],
好了,事實證明茉莉2.0移除runs()
waits()
和waitsFor()
新的異步支持使用done()
,可在以下位置找到: http : //jasmine.github.io/2.0/introduction.html#section-Asynchronous_Support 。 我已經在過時的github wiki頁面上添加了一個快速注釋。
基本上,如果你想運行異步測試,你應該使用$ httpBackend服務,當刷新時會觸發正確的事件,你的測試將順利運行。
編輯:每個angularjs定時動作都包含在promises和digest循環中。 如果$timeout
觸發了觸發它的摘要周期,你可以執行$timeout.flush()
。
例如,您可以:
expect($scope.timedvariable).toEqual('before timeout value');
// Flush the timeout service
$timeout.flush();
// the actions within the $timeout are executed
expect($scope.timedvariable).toEqual('value after timeout');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.