Javascript Jasmine和Karma:找不到变量运行
我是否需要一个插件/lib来与Jasmine一起使用runs()和waits()?我正在查看Jasmine wiki页面上的异步测试: 他们没有提到需要一个特殊的库/插件,所以我假设runs()和waits()应该是现成的 我的代码如下所示(它被包装在一个描述中): 我得到:Javascript Jasmine和Karma:找不到变量运行,javascript,angularjs,testing,jasmine,karma-runner,Javascript,Angularjs,Testing,Jasmine,Karma Runner,我是否需要一个插件/lib来与Jasmine一起使用runs()和waits()?我正在查看Jasmine wiki页面上的异步测试: 他们没有提到需要一个特殊的库/插件,所以我假设runs()和waits()应该是现成的 我的代码如下所示(它被包装在一个描述中): 我得到:ReferenceError:未定义运行 我的业力配置的相关部分是: files: [ 'bower_components/jquery/dist/jquery.min.js', 'b
ReferenceError:未定义运行
我的业力配置的相关部分是:
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'
],
基本上,如果您想要运行异步测试,您应该使用该服务,当刷新该服务时,它将触发正确的事件,您的测试将顺利运行 编辑: angularjs的每一个定时动作都包含在承诺和摘要周期中。在
$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');
好的,原来Jasmine 2.0已经删除了
runs()
,waits()
和waitsFor()
。新的异步支持使用done()
,可在以下位置找到:。我已经在过时的github wiki页面上添加了一条关于这一点的快速说明。啊,好吧,但我没有在我的框架中使用'ng-scenario'
:['jasmine']
?另外,我只是尝试测试一个向元素添加类的指令,然后在$timeout之后删除该类。所以我不认为我需要$httpBackend,而是runs()和waitis()。@user2736286我编辑了我的帖子,用正确的信息更正了它,并为你添加了一个关于如何正确刷新angularjs中的超时的提示。这虽然很有帮助,但并没有回答人们提出的问题。它还应该解决被问到的问题:为什么Jasmine找不到运行
。
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');