jasmine

How can I make jasmine.js stop after a test failure?

自作多情 提交于 2019-12-22 04:01:06
问题 I want the runner to stop after the first failure rather than running all the tests. 回答1: It's a hack, but you can do this by inserting this script before your first test; <script type="text/javascript"> // after every test has run afterEach(function () { // check if any have failed if(this.results_.failedCount > 0) { // if so, change the function which should move to the next test jasmine.Queue.prototype.next_ = function () { // to instead skip to the end this.onComplete(); } } }); </script>

Protractor error Angular could not be found on the page

故事扮演 提交于 2019-12-22 03:48:06
问题 I'm trying to set up End-2-End testing for my Angular (1.4) site using protractor (2.1.0). Jasmine is installed and unit tests are working fine. When I run protractor the index#/login page loads in a browser window but no code runs and protractor reports this error Failed: Angular could not be found on the page http://localhost/SpectrumGMWeb/index.html#/login : retries looking for angular exceeded My protractor config looks like this exports.config = { allScriptsTimeout: 11000,

Lifecycle hook of AfterViewInit in Jasmine test

假装没事ソ 提交于 2019-12-22 03:27:04
问题 I am confused on lifecycle hooks in relationship with Jasmine testing. The LifeCycle Angular doc does not mention testing https://angular.io/guide/lifecycle-hooks. The testing doc only mentions OnChange https://angular.io/guide/testing. I have a sample component as follows: import { Component, OnInit, AfterViewInit, OnDestroy, ElementRef } from '@angular/core'; ... @Component({ selector: 'app-prod-category-detail', templateUrl: './prod-category-detail.component.html', styleUrls: ['./prod

Angular2, testing and resolved data: how to test ngOnINit?

有些话、适合烂在心里 提交于 2019-12-22 02:51:10
问题 I'm working through the Angular2 testing guide and wish to write a test for the ngOnInit() function. The one from the Routing part of the programming guide has this format: let org: Org = null; ngOnInit(): void { let that = this; this.route.data .subscribe((data: { org: Org }) => { that.org = data.org; }); } This is fulfilled through a resolver, like: resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Org> { let id = this.authService.user.orgId; return this

Mock window.location.reload in Jasmine testing

心已入冬 提交于 2019-12-22 02:00:54
问题 I have created a window.location.reload function in my javascript. I need to mock the reload function while testing in Jasmine since it keeps on looping. The test goes well when I run grunt jenkins . But not while testing in the browser (mozilla/chrome). Here is my code snippet. Javascript: window.location.reload(); Jasmine Test: spyOn(window.location, 'reload').and.callFake(function(){}); Can anyone please help me on this? 回答1: Thanks for sharing your views. I did a work around as suggested

How can I mock an Observable.throw in an Angular2 test?

泪湿孤枕 提交于 2019-12-22 01:55:17
问题 I want to test the error handling in my Angular2 component and therefore want to mock a service to return an Observable.throw('error'). How can that be done using Jasmine and Karma and Angular 2? 回答1: You should create an observable, and just call the observer error . For example let mockService = { error: false, data: 'something', getData: () => { return Observable.create(observer => { if (this.error) { observer.error(new Error(..)) } else { observer.next(this.data); } observer.complete(); }

Mock window.location.reload in Jasmine testing

落花浮王杯 提交于 2019-12-22 01:54:26
问题 I have created a window.location.reload function in my javascript. I need to mock the reload function while testing in Jasmine since it keeps on looping. The test goes well when I run grunt jenkins . But not while testing in the browser (mozilla/chrome). Here is my code snippet. Javascript: window.location.reload(); Jasmine Test: spyOn(window.location, 'reload').and.callFake(function(){}); Can anyone please help me on this? 回答1: Thanks for sharing your views. I did a work around as suggested

Is it possible to send a reason for Jasmine 2 specs skipped with xit or pending()?

大兔子大兔子 提交于 2019-12-22 01:41:02
问题 When we find a bug with one of our Protractor Jasmine2 specs, we usually want to skip the test until the bug has been resolved. I know how to do this with xit or pending() , and JasmineReporters TerminalReporter is doing a nice job of color highlighting and listing pending specs. However, the pending tests always report No reason given , which implies it is possible to give a reason for the skipped test. I currently comment the spec with an issue number, but it would be really nice to report

TypeScript - jasmine - Chutzpah - AngularJS

半腔热情 提交于 2019-12-22 01:17:18
问题 Hi we are using angulatJs with typescript. For unit testing we are using Jasmine. And to run jasmine we are using Chutzpah . When i am trying to build project it giving me an error that ReferenceError: Can't find variable: angular Where i have added reference to the .spect.ts correctly. ///<reference path="../external/angularJS/1.0.8/angular.d.ts" /> ///<reference path="../external/angularJS/1.0.8/angular-ui.d.ts" /> ///<reference path="../external/angularJS/1.0.8/angular-mocks.d.ts" /> ///

Generate simple html based on jasmine-allure-reporter

老子叫甜甜 提交于 2019-12-22 00:31:01
问题 I'm using jasmine-allure-reporter and the report is simply awesome. Only complaint over the reporter is that I miss option to enable only failed screenshots to be saved and possibility to send it via e-mail. I know that is not possible: How to send an email of allure report? My question is whether I can somehow generate a simple html file with few data based on the allure reports, so that I'll be able to send it via e-mail to relevant people. 回答1: Hope you have added this in your conf file: