karma-jasmine

How to get around memory error with karma & phantomjs

泪湿孤枕 提交于 2019-12-03 06:54:03
问题 We're running tests using karma and phantomjs Last week, our tests mysteriously started crashing phantomJS with an error of -1073741819. Based on this thread for Chutzpah it appears that code indicates a native memory failure with PhantomJS. Upon further investigation, we are consistently seeing phantom crash around 750MB of memory. Is there a way to configure Karma so that it does not run up against this limit? Or a way to tell it to flush phantom? We only have around 1200 tests so far. We

Conditionally ignore individual tests with Karma / Jasmine

こ雲淡風輕ζ 提交于 2019-12-03 04:45:12
I have some tests that fail in PhantomJS but not other browsers. I'd like these tests to be ignored when run with PhantomJS in my watch task (so new browser windows don't take focus and perf is a bit faster), but in my standard test task and my CI pipeline, I want all the tests to run in Chrome, Firefox, etc... I've considered a file-naming convention like foo.spec.dont-use-phantom.js and excluding those in my Karma config, but this means that I will have to separate out the individual tests that are failing into their own files, separating them from their logical describe blocks and having

KarmaJS, Jasmine, RequireJS, etc: How to Use Require for Testing Modules

断了今生、忘了曾经 提交于 2019-12-03 04:18:57
问题 Running Karma + Jasmine Tests with RequireJS -- Getting off the ground Help! . . . _ _ _ . . . SOS! Currently, I have an exercise project up for getting comfortable with KarmaJS -- and Unit Testing, at large. The broad issue is that I really have no transparent view of what Karma is doing behind the scenes, and I can't seem to find adequate documentation in relevant areas. Without further delay... Here is my folder structure : root |-/lib |-/[dependencies] (/angular, /angular-mocks,

Debug Tests in NG Test

这一生的挚爱 提交于 2019-12-03 03:37:51
问题 I am using Angular CLI and VS code but none of my breakpoints in my spec files seem to be getting hit when I run ng test? Do I need to do some config? 回答1: The other answers are completely valid answers but having been using Angular for around 18 months now I tend to do it in the browser - chrome tools! Run ng test then f12 and find the spec file via the webpack context. Add a breakpoint(s) and refresh and it will hit said breakpoints. As per screenshot 回答2: Angular 8.2.13 + Visual Studio

Error: Cannot find module 'jasmine-core'

落爺英雄遲暮 提交于 2019-12-03 03:24:38
I installed the following for testing: "devDependencies": { "jasmine-core": "^2.4.1", "karma": "^0.13.22", "karma-jasmine": "^0.3.7", "karma-phantomjs-launcher": "^1.0.0" } After running karma start I get the following error: Doing a search this is the first question with the same problem: karma start Cannot find module 'jasmine-core' However I've tried both answers, installed jasmine-core globally and I already did npm install jasmine-core --save-dev :( My test/index.html <!DOCTYPE html> <html lang="en"> <head> <title>Jasmine Spec Runner</title> <link href="testing.css" rel="stylesheet">

Angular unit testing with Jasmine: how to remove or modify spyOn

吃可爱长大的小学妹 提交于 2019-12-03 02:59:39
问题 AngularJS v1.2.26 Jasmine v2.2.0 How can I change or remove the behavior of a spyOn ? When I try to override it, I get the following error: Error: getUpdate has already been spied upon var data1 = 'foo'; var data2 = 'bar'; describe("a spec with a spy", function(){ beforeEach(module('app')); var $q; beforeEach(inject(function(_updateService_, _$q_){ updateService = _updateService_; //spy the results of the getUpdate() $q = _$q_; var deferred = $q.defer(); deferred.resolve( data1 ); spyOn

Angular2 NgModel not getting value in Jasmine test

孤街浪徒 提交于 2019-12-03 02:50:41
I am using template-driven forms in Angular 2, and I'm trying to develop them test-first. I've scoured this site and the rest of the internet and I've tried basically everything I can find (mainly bunches of tick() statements and detectChanges() everywhere in a fakeAsync) to get the NgModel attached to my input to pick up the value so it can be passed to my onSubmit function. The value of the input element sets properly, but the NgModel never updates, which then means the onSubmit function does not get the correct value from the NgModel. Here's the template: <form id="createWorkout" #cwf=

Testing Angular component with unsubscribe Error during cleanup of component

和自甴很熟 提交于 2019-12-03 02:40:21
问题 I'm testing a component which subscribe router params. Every test pass and everything works fine. But if I look in the console, I can see an error: Error during cleanup of component ApplicationViewComponent localConsole.(anonymous function) @ context.js:232 Do you know why this occurs? I tried removing the unsubscribe() from ngOnDestroy() method and the error disappears. Is karma/jasmine supporting unsubscribe() automatically? Here is the component and tests Component import { Component,

How to mock AngularFire 2 service in unit test?

夙愿已清 提交于 2019-12-03 02:09:35
I'm trying to set up unit tests for a sample Angular 2 app using AngularFire 2 auth, the component is fairly simple: import { Component } from '@angular/core'; import { AngularFire, AuthProviders } from 'angularfire2'; @Component({ moduleId: module.id, selector: 'app-root', templateUrl: 'app.component.html', styleUrls: ['app.component.css'] }) export class AppComponent { isLoggedIn: boolean; constructor(public af: AngularFire) { this.af.auth.subscribe(auth => { if (auth) { this.isLoggedIn = true; } else { this.isLoggedIn = false; } }); } loginWithFacebook() { this.af.auth.login({ provider:

Angular 2.0.0 - Testing “ imported by the module 'DynamicTestModule' ”

那年仲夏 提交于 2019-12-03 01:25:56
I am having a problem in testing app.component.ts in Angular 2. I am using angular-cli. Whenever I run ng test, my app.component.spec.ts makes the console prompt with the error: Failed: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule' Error: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule' I imported the HomeModuleComponent in TestBed TestBed.configureTestingModule({ declarations: [AppComponent], imports : [ HomeModuleComponent ] }); Can anyone help me with this problem? manjunath shanbhag HomeModuleComponent is