karma-jasmine

How to test a sound is playing?

不打扰是莪最后的温柔 提交于 2019-12-03 12:32:27
问题 I've been trying to cover <audio> tag by automated tests, to start with just to confirmed it is playing. I'm using the usual angular test suite, karma and protractor. "devDependencies": { "karma": "~0.10", "protractor": "~0.20.1", "http-server": "^0.6.1", "bower": "^1.3.1", "shelljs": "^0.2.6", "karma-junit-reporter": "^0.2.2", "grunt": "~0.4.1", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-watch": "~0.4.3" } On the Karma side the issue is I couldn't find

Branches on constructor not covered

我是研究僧i 提交于 2019-12-03 12:25:31
I am creating my unit tests with Jasmine and I have a question about the branch covered. Does anyone know why the code part shows that the branches are not covered as we can see below? This is the unit test: describe('MyComponent', () => { let component: MyComponent; let fixture: ComponentFixture<MyComponent>; let myService: MyService; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ MyComponent ], imports: [ MaterializeModule, FormsModule, ReactiveFormsModule, HttpModule ], providers: [ MyService, FormBuilder ] }) .compileComponents(); })); beforeEach(() => { fixture

Angular2 NgModel not getting value in Jasmine test

爷,独闯天下 提交于 2019-12-03 12:23:57
问题 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

How to mock AngularFire 2 service in unit test?

纵饮孤独 提交于 2019-12-03 11:33:56
问题 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 =

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

那年仲夏 提交于 2019-12-03 10:58:48
问题 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 : [

Mock custom service in angular2 during unit test

北城以北 提交于 2019-12-03 10:17:06
I'm trying to write a unit test for component used in my service. Component and service work fine. Component: import {Component} from '@angular/core'; import {PonyService} from '../../services'; import {Pony} from "../../models/pony.model"; @Component({ selector: 'el-ponies', templateUrl: 'ponies.component.html', providers: [PonyService] }) export class PoniesComponent { ponies: Array<Pony>; constructor(private ponyService: PonyService) { this.ponies = this.ponyService.getPonies(2); } refreshPonies() { this.ponies = this.ponyService.getPonies(3); } } Service: import {Injectable} from "@angular

AngularJS Jasmine Test Fails: Failed to instantiate module

折月煮酒 提交于 2019-12-03 09:41:51
My angular app worked great and so did my tests, using karma and jasmine, until I added a dependency in ui.bootstrap . Now the app still works as expected, but I can't get my tests to run. This is what I have: app.js - added dependency in ui.bootstrap angular.module('myApp', ['ngResource', 'ngRoute', 'ui.bootstrap']).config(function(...) {...}); service.js angular.module('myApp').service('myService', function () {}) controller.js angular.module('myApp').controller('MyController', function ($scope, $http, myService) {}) tests/main.js describe('Controller: MyController', function () { var

TypeError: undefined is not a constructor

£可爱£侵袭症+ 提交于 2019-12-03 09:25:08
I'm very new to Angular and I'm trying to figure much of this out still. I'm writing some tests using Angular 1.5.8 which I generated from the Yeoman Generator. Specifically, I'm trying to figure out how to manipulate $httpBackend results (I'm not sure if that's important or not)... In my app.js file I have the following code: .run(['$rootScope', '$location', 'breadcrumbService', function ($rootScope, $location, breadcrumbService) { $rootScope.$on('$viewContentLoaded', function () { jQuery('html, body').animate({scrollTop: 0}, 200); }); $rootScope.isEditMode = false; $rootScope.$on('

Angular testing submit event on reactive form

寵の児 提交于 2019-12-03 09:23:15
Context I have a component with a basic form (reactive form). I try to test the submit event on this form to see if it calls the necessary method properly. My problem I can't trigger the submit event of the form Files Component.html <form class="form-horizontal" id="staticForm" [formGroup]="mySimpleForm" (ngSubmit)="sendMethod();" > <input type="text" formGroupName="email"> <button type="submit">Send form</button> </form> Component.ts ngOnInit() { this.initSimpleForm(); } private initSimpleForm() { let file = null; this.mySimpleForm = this.formBuilder.group({ email: [ '', [ Validators.required

How to spy on anonymous function using Jasmine

↘锁芯ラ 提交于 2019-12-03 08:03:59
I'm using Jasmine to test my angular application and want to spy on an anonymous function. Using angular-notify service https://github.com/cgross/angular-notify , I want to know whether notify function have been called or not. Here is my controller: angular.module('module').controller('MyCtrl', function($scope, MyService, notify) { $scope.isValid = function(obj) { if (!MyService.isNameValid(obj.name)) { notify({ message:'Name not valid', classes: ['alert'] }); return false; } } }); And here is my test: 'use strict'; describe('Test MyCtrl', function () { var scope, $location, createController,