karma-jasmine

How to test browserify project using karma/jasmine

帅比萌擦擦* 提交于 2019-12-02 08:32:03
问题 I'm totally new to the concept of testing, and i need one solid example on how to do it in my project: I have a gulp file goes like this (Not all of it, just the important portions) gulp.task('bundle', function() { gulp.src('public/angular-app/main.js') .pipe(browserify({ debug: true })) .pipe(gulp.dest('public/min-js')); }); This is a slight portion of my main.js: 'use strict'; angular.module('myApp', [ 'ui.router', 'ui.bootstrap', 'ngSanitize', 'ngFx', ... ], ['$interpolateProvider',

How do I unit test $scope.broadcast, $scope.$on using Jasmine

混江龙づ霸主 提交于 2019-12-02 08:01:00
I'm newbie to AngularJs/NodeJs world, so forgive if this is a basic question to some. So in a nutshell I've two controllers, the first controller $broadcast an 'Id' and the second controller fetches that Id with $on and then passes that Id to an intermediate service , which makes an $http ajax call and returns a single Book object. How do I unit test $scope.broadcast, $scope.$on using Jasmine firstCtrl .controller('firstCtrl', function($scope, ...){ $scope.selectGridRow = function() { if($scope.selectedRows[0].total !=0) $scope.$broadcast('id', $scope.selectedRows[0].id);//Just single plain ID

Angular Material 2 - Trigger change event in md-checkbox in a Unit Test

人走茶凉 提交于 2019-12-02 07:44:16
I am having problems triggering a 'change' event for a md-checkbox in an Angular Unit Test, using the test framework setup provided by the Angular CLI. I have a simple component: ts: import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { checkedValue = 'false'; result = false; checkValueChange(event) { console.log('CheckBox clicked: ' + event.checked); this.result = true; } } template: <md-checkbox [checked]="true" [(ngModel)]="checkedValue" (change)="checkValueChange(

How to test browserify project using karma/jasmine

眉间皱痕 提交于 2019-12-02 07:29:14
I'm totally new to the concept of testing, and i need one solid example on how to do it in my project: I have a gulp file goes like this (Not all of it, just the important portions) gulp.task('bundle', function() { gulp.src('public/angular-app/main.js') .pipe(browserify({ debug: true })) .pipe(gulp.dest('public/min-js')); }); This is a slight portion of my main.js: 'use strict'; angular.module('myApp', [ 'ui.router', 'ui.bootstrap', 'ngSanitize', 'ngFx', ... ], ['$interpolateProvider', function($interpolateProvider) { $interpolateProvider.startSymbol('{{'); $interpolateProvider.endSymbol('}}')

Storing global variable in a separate file for Protractor Tests

本小妞迷上赌 提交于 2019-12-02 06:50:24
I am trying to create a separate inventory file for Protractor Test where I can store all the reusable variable to be used by different test scrips. The sample Variable list is called Vars.js and the specs should import the variables from this file and consume those. However, this fails as shown below. Can this approach actually be used for storing reusable variables? Can I actually create a separate inventory file for protractor tests outside of conf.js? Vars.js has the following content : "use strict"; exports.config = { function() { global.loginMain = 'https://mytestsite.com/auth/login';

error: No provider for @Attribute('sampleString')

拟墨画扇 提交于 2019-12-02 06:26:16
问题 We are trying to write unit test for a component which uses a third party java script library. The constructor of our component looks like - @Constructor(@Inject(ElementRef) private eleref:ElementRef, @Attribute('sampleString') private sampleString: string) We use that attribute to pass it to my third party library. And in there it does a specific task based on that attribute. If I don't pass it, it means simply ignore it and do regular stuff. When we try to use/inject this component in our

AngularJS : Testing factory that returns $http promises

徘徊边缘 提交于 2019-12-02 04:14:12
Trying to test an angular service that returns an $http GET request and the then handler, but I'm not able to test that the logic actually works inside of the then function. Here is a basic, truncated version of the service code: angular.module('app').factory('User', function ($http) { var User = {}; User.get = function(id) { return $http.get('/api/users/' + id).then(function (response) { var user = response.data; user.customProperty = true; return user; }); }; return User; }); And here is the test: beforeEach(module('app')); beforeEach(inject(function(_User_, _$q_, _$httpBackend_, _$rootScope

Test subscribing to Location in angular 2 with karma+jasmine (this.location.subscribe)

萝らか妹 提交于 2019-12-02 04:03:45
问题 I am subscribing to the angular Location service in my component as such: this.location.subscribe((ev:PopStateEvent) => { this.lastPoppedUrl = ev.url; }); I'd like to be able to test it along with the rest of my component. Right now I have this stub in my component.spec.ts file let locationStub: Partial<Location>; locationStub = { } And I am configuring it into my TestBed as a provider: {provide: Location, useValue: locationStub } When I run ng test , I get this error this.location.subscribe

error: No provider for @Attribute('sampleString')

拈花ヽ惹草 提交于 2019-12-02 01:26:02
We are trying to write unit test for a component which uses a third party java script library. The constructor of our component looks like - @Constructor(@Inject(ElementRef) private eleref:ElementRef, @Attribute('sampleString') private sampleString: string) We use that attribute to pass it to my third party library. And in there it does a specific task based on that attribute. If I don't pass it, it means simply ignore it and do regular stuff. When we try to use/inject this component in our test class, it gives us error. Error: DI Exception: No Provider for @Attribute('sampleString')! Can

Explain karma unit test times

落花浮王杯 提交于 2019-12-02 01:08:24
I've been searching the web for this for two days and I found nothing. Maybe I'm looking in the wrong way — I don't know... So here it is: what are the times on my console when running a Karma+Jasmine+phantomJs unit test? ... Executed 1 of 1 SUCCESS (0.878 secs / 0.112 secs) First, I though that the second time is the total unit test time (for example, when running multiple tasks), however, sometimes the first time gets to be 'bigger', sometimes not... Anyone? total time / net time net time = only test execution (in the browser) total time = how long it took since Karma noticed the file change