我遇到了一个问题,当我在Jasmine上运行测试时,我在下面收到此错误.问题是,当我尝试执行一定数量的测试时,似乎会发生这种情况.它似乎与特定的测试无关,就好像我注释掉了一些,测试通过了.如果我取消注释某些测试,则会出现错误.如果我注释掉之前没有注释的那些,它们都会再次通过.(即如果我有红色,绿色,蓝色和橙色测试但它失败了,我会将橙色和蓝色评论通过,然后我取消注释蓝色和橙色它再次失败,但如果我注释掉红色和绿色它再次通过).
Chrome 41.0.2272(Mac OS X 10.10.1)错误您的一些测试执行了整页重新加载!Chrome 41.0.2272(Mac OS X 10.10.1):执行16 of 29(1失败)错误(0.108秒/0.092秒)
我对发生的事感到难过.我添加的测试越多,这就成了问题.有没有人遇到过这个?我不知道是什么导致它,因为我的任何测试都没有做任何类型的重定向,并且它们都普遍通过另一台人机.
我有一个相当简单的karma.config.js文件
basePath = '../';
files = [
JASMINE,
JASMINE_ADAPTER,
'js/lib/angular*.js',
'test/lib/angular/angular-mocks.js',
'js/**/*.js',
'test/unit/**/*.js'
];
autoWatch = true;
browsers = ['PhantomJS'];
Run Code Online (Sandbox Code Playgroud)
当我跑步时,karma start config/karma.conf.js --single-run我得到以下输出
$ karma start config/karma.conf.js --single-run
[2013-06-24 23:47:08.750] [DEBUG] config - autoWatch set to false, because of singleRun
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9 (Mac)]: Connected on socket id LwMoWxzIbSUuBsvIqB_m
PhantomJS 1.9 (Mac): Executed 6 of 6 SUCCESS (0.073 secs / 0.02 secs)
Run Code Online (Sandbox Code Playgroud)
我一直在寻找一些东西来告诉我如何获得记录的测试输出(例如SUCCESS Unit: …
expect(view.$el.html()).toContain('Admin');
Run Code Online (Sandbox Code Playgroud)
视图确实包含"管理员"这个词,所以我希望它返回true.我怎样才能做到这一点?
expect(view.$el.html()).toContain('Admin');
Run Code Online (Sandbox Code Playgroud)
这回来了undefined.我怎样才能让它回归true?
<header class="main">
<div id="heading">
<ul class="header-view right">
<li class="inline"><a href="#link" class="button help-btn tab-btn"><span> </span>Help</a></li>
<li class="inline last"><a href="#og" class="button admin-btn tab-btn expand-admin"><span></span>Admin</a></li>
</ul>
</div>
</header>
Run Code Online (Sandbox Code Playgroud)
这是从中返回的 view.$el.html
请帮忙.
我正在测试订阅路由器参数的组件.每个测试通过,一切正常.但如果我查看控制台,我会看到一个错误:
清理组件ApplicationViewComponent localConsole时出错.(匿名函数)@ context.js:232
你知道为什么会这样吗?
我尝试删除unsubscribe()from ngOnDestroy()方法,错误消失.
karma/jasmine会unsubscribe()自动支持吗?
这是组件和测试
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs/Rx'
import { AppService } from 'app.service';
@Component({
selector: 'app-component',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
private routeSubscription: Subscription;
// Main ID
public applicationId: string;
constructor(
private route: ActivatedRoute,
private _service: AppService
) { }
ngOnInit() {
this.routeSubscription = this.route.params.subscribe(params => { …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular CLI和VS代码,但是当我运行测试时,我的spec文件中的所有断点似乎都没有受到影响?
我需要做一些配置吗?
我使用Yeoman安装了Karma和karma-jasmine,如下所示:
$ npm install -g generator-angular
$ mkdir myapp && cd $_
$ yo angular
Run Code Online (Sandbox Code Playgroud)
鉴于myapp/bower.json没有将Jasmine列为Bower安装的前端软件包之一,但myapp/karma.conf.js将Jasmine列为默认测试框架,我对命令grunt test工作感到惊讶.(本Gruntfile.js,bower.json以及karma.conf.js文件被作为一部分的所有创建yo angular脚手架的过程.)
仔细检查myapp/node_modules包装后,我意识到karma-jasmine并没有指向单独安装Jasmine.在卡玛-茉莉插件实际安装茉莉花 …
我试图更新我的整个项目依赖项,并设法做到这一点,但是当我尝试运行测试时,ng test --no-watch它们不起作用,给我以下错误。
23 11 2022 12:33:58.268:INFO [Chrome Headless 107.0.5304.107 (Windows 10)]: Connected on socket JpJqOsJswlYxFGjeAAAB with id 12720855
Chrome Headless 107.0.5304.107 (Windows 10) ERROR
An error was thrown in afterAll
Uncaught TypeError: __webpack_require__(...).context is not a function
TypeError: __webpack_require__(...).context is not a function
at Object.4289 (http://localhost:9876/_karma_webpack_/webpack:/src/test.ts:18:25)
at __webpack_require__ (http://localhost:9876/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at __webpack_exec__ (http://localhost:9876/_karma_webpack_/main.js:10483:48)
at http://localhost:9876/_karma_webpack_/main.js:10484:54
at Function.__webpack_require__.O (http://localhost:9876/_karma_webpack_/webpack:/webpack/runtime/chunk loaded:23:1)
at http://localhost:9876/_karma_webpack_/main.js:10485:56
at webpackJsonpCallback (http://localhost:9876/_karma_webpack_/webpack:/webpack/runtime/jsonp chunk loading:71:1)
at http://localhost:9876/_karma_webpack_/main.js:1:87
Chrome Headless 107.0.5304.107 (Windows 10): Executed 0 of 0 ERROR …Run Code Online (Sandbox Code Playgroud) 有没有办法从业力覆盖运行员https://github.com/karma-runner/karma-coverage的代码覆盖率报告中排除文件 ?
我对Angular很新,而且我还在努力解决这个问题.我正在使用我从Yeoman Generator生成的Angular 1.5.8编写一些测试.
具体来说,我正在试图弄清楚如何操纵$ httpBackend结果(我不确定这是否重要)...
在我的app.js文件中,我有以下代码:
.run(['$rootScope', '$location', 'breadcrumbService', function ($rootScope, $location, breadcrumbService) {
$rootScope.$on('$viewContentLoaded', function () {
jQuery('html, body').animate({scrollTop: 0}, 200);
});
$rootScope.isEditMode = false;
$rootScope.$on('$stateChangeSuccess', function () {
// ------------ this next line is failing -----------
$rootScope.isEditMode = $location.path().toLowerCase().endsWith('/edit') || $location.path().toLowerCase().endsWith('/new');
});
$rootScope.parseJson = function (value) {
return angular.fromJson(value);
};
$rootScope.bc = breadcrumbService;
$rootScope.title = "";
}])
Run Code Online (Sandbox Code Playgroud)
大约一半的线(我添加评论的地方)失败了.具体来说,endsWith函数失败(toLower很好),出现此错误:
PhantomJS 2.1.1 (Windows 8 0.0.0) Service: breadcrumbService should return breadcrumb label in json format FAILED
TypeError: undefined is …Run Code Online (Sandbox Code Playgroud) 我担心有人会提出我的问题,但我找不到令人满意的问题(也许是因为我在Angular 2+世界中非常有限,我理解错了).
据我所知,在完成了几个Hello World之后我很难理解,很少有YouTube演示观看:
ng测试:
xxx.compnent.spec.ts运行,并在浏览器中显示类似于JUnit的最终报告ng e2e:
您在编写嵌套用户事件时编写测试
eg. page.navigateTo();
page.getParagraphText()
.then(msg => expect(msg).toEqual('Welcome to app!!'))
.then(msg => expect(msg).toEqual('xxx'))
.then(done, done.fail);
Run Code Online (Sandbox Code Playgroud)您使用量角器执行端到端测试主要是在部署应用程序后的一种预生产环境
Theoracly说,第二个是特定的端到端,其重点是模拟最终用户完成的整个流程.
希望,直到这里是正确的,我想知道幕后发生了什么真正使他们与众不同.我不想比较哪个更好但是我肯定错过了一些点,因为我使用完全相同的想法创建了一些测试,并且我通过ng测试触发了它.
例如:
...
it('should display the modal when `create Paste` is clicked', () => {
let createPasteButton = fixture.debugElement.query(By.css("button"));
//create a spy on the createPaste method
spyOn(component,"createPaste").and.callThrough();
//triggerEventHandler simulates a click event on the button object
createPasteButton.triggerEventHandler('click',null);
//spy checks whether the method was called
expect(component.createPaste).toHaveBeenCalled();
fixture.detectChanges();
expect(component.showModal).toBeTruthy("showModal should …Run Code Online (Sandbox Code Playgroud) karma-jasmine ×10
angular ×4
jasmine ×4
javascript ×4
karma-runner ×4
angular-cli ×2
angularjs ×2
jquery ×1
node.js ×1
phantomjs ×1
protractor ×1
typescript ×1
unit-testing ×1
webpack ×1