jasmine

Gitlab CI running Angular Jasmine tests crashing without error

我的梦境 提交于 2020-01-06 06:32:58
问题 Having just setup Gitlab CI to run the Jasmine tests in my Angular project, I found the pipeline would bomb out with very little indication of the cause. All my tests would pass when run locally using ng test or locally in headless Chrome (having followed docs and another guide to set that up). However, the pipeline would get to around 13/90 tests and then disconnect. Here's a sample of the debug output (with logLevel: config.LOG_DEBUG in karma.conf.js ): HeadlessChrome 74.0.3723 (Linux 0.0.0

jasmine unit tests for datetimepicker click event function

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-05 07:18:21
问题 Can any body suggest to write test case for this code which is in Jquery $('#issueDateSpan').click(function(event) { event.preventDefault(); $('#datetimepickerIssue').data('DateTimePicker').show(); }); 来源: https://stackoverflow.com/questions/39632316/jasmine-unit-tests-for-datetimepicker-click-event-function

Test the addition of a route via ConfigureRouter. How do we see the NavModel?

旧巷老猫 提交于 2020-01-05 05:01:17
问题 In the following test, the router.navigation property has a length of zero. How do we access our routes NavModel ? import { Container } from "aurelia-framework"; import { RouterConfiguration, Router } from "aurelia-router"; describe("the RouterConfiguration", function () { let container: Container = new Container(); let routerConfiguration: RouterConfiguration = container.get(RouterConfiguration); let router: Router = container.get(Router); it("adds a route with a NavModel", function (done) {

Angular 2 - Mocking - response is null

你离开我真会死。 提交于 2020-01-05 04:05:12
问题 Angular 2.0.0 - Ionic 2 RC0 - Npm 3.10.8 - Node v4.5.0 - Karma 1.3.0 - Jasmine 2.5.2 previous question: Angular 2 -- Mocking - No Provider for HTTP I'm now getting a new error while executing npm test : null is not an object (evaluating '_this.events.length') Which is triggered by this code: if(this.events.length > 0){ in EventsPage which means my response I set in events.spec.ts is somehow not properly returned. I'm new to mocking Angular2 so it's moest likely a rookie mistake. (changed some

How to expect an asynchronously thrown exception in Jasmine / Angular2 / Typescript?

三世轮回 提交于 2020-01-05 04:04:45
问题 Given an Angular2/Typescript method that returns nothing and implements a .subscribe() handler which might throw, such as this: onSubmit() { // returns nothing this.service.someCall(this.someData).subscribe( data => { return Promise.reject('This is an asynchronously thrown error.'); }, err => {}, ); } (For the moment, let's assume that there's a good reason for this .subscribe() handler to (probably conditionally) reject without other testable side-effects, thus resulting only in an error

Can not get element in directive while testing AngularJs + Jasmine

帅比萌擦擦* 提交于 2020-01-04 23:24:27
问题 I've got an angularjs directive with external template. It works well but I can not write jasmine unit tests for it. Here is plunker reproduced code: http://plnkr.co/edit/JPOBm7?p=preview All my tries failed on the same issue. Link method crashes on getting template's DOM element while running unit-test. It says: TypeError: canvas is null in http://run.plnkr.co/YHHxxmSgCiQxjrjw/app.js (line 8) I have no idea how to make it work. Help, please. My simplified directive code: angular.module('app'

Loading jQuery into Grunt.js using the grunt-contrib-jasmine plugin

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 12:36:50
问题 I am trying to load jQuery into my tests using Grunt.js and the grunt-contrib-jasmine plugin. Here is a gist of my Gruntfile.js and I've referenced jQuery in the jasmine.options.vendor array as the documentation suggests. https://gist.github.com/anonymous/4751371 However, when I run a very simple test, it fails because jQuery isn't getting loaded: describe('like module', function() { var $ul; beforeEach(function() { $ul = $('<ul><li class="no-results"></li></ul>'); }); it('should test the

Angular2 test if component has proper selector

霸气de小男生 提交于 2020-01-04 08:05:07
问题 Is there any possibility in Angular2 to verify component selector with unit test? e.g. @Component({ selector: 'my-component', template: '<p>test</p>' }) export class MyComponent {} and .... it(`Component should have selector 'my-component'`, () => { expect(component.selector).toBe('my-component'); }); 回答1: Reflect metadata is used by Angular DI to store and retrieve decorator data. It is possible to get metadata from the class and assert it: const [componentDecorator] = Reflect.getOwnMetadata

How to write Angular Jasmine simple 'should create' test case using shallow-render instead of using NO_ERRORS_SCHEMA

痴心易碎 提交于 2020-01-04 07:01:52
问题 I have a few angular (v6) components whose template contains RouterLink reference. These components have the default generated test case entitled 'should create', which breaks with the error: Can't bind to 'routerLink' since it isn't a known property of 'a'. ("12"> I can fix this using NO_ERRORS_SCHEMA, for example: beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ NotFoundComponent ], schemas: [NO_ERRORS_SCHEMA] }) .compileComponents(); })); But the problem with using

unit test angular service not able to reach function inside service + jasmine

不想你离开。 提交于 2020-01-04 05:32:27
问题 I have written some service in angular. Check this PLUNKER. Injecting CommonService, $rootRouter, ModalService in RouteService . I am stuck with unit testing these services. You can see sample spec file at PLUNKER. EDIT: Whatever test I have at plunker are not working as expected. Am not sure what I am doing wrong. How to test goTo and getActivePage methods in RouteService ? How to test getProperty and setProperty methods in CommonService ? Here is code. First service is RouteService 'use