karma-jasmine

Karma + jasmine + angular + ui router - testing for resolve with state.go with params

白昼怎懂夜的黑 提交于 2019-12-05 13:18:37
I have state defined in my angular module "moduleB" as follows $stateProvider .state('stateB', { parent: 'stateA', abstract: true, templateUrl : baseUrl+'/templates/stateB.html' }) .state('stateB.details', { url: '/stateB/details/:param1/:param2', resolve : { value3 : ['$localStorage', '$stateParams', function($localStorage, $stateParams){ return $localStorage.value3[$stateParams.param1]; }] }, views : { 'view1' : { templateUrl : baseUrl+'/templates/view1.html', controller: 'View1Ctrl' }, 'view2' : { templateUrl : baseUrl+'/templates/view2.html', controller : 'View2Ctrl' } } }) I would like to

Angular: Unit Testing Routing : Expected '' to be '/route'

亡梦爱人 提交于 2019-12-05 12:13:04
Am working on unit testing for my routing under my Angular app , My routes are delacred in a specific module which is imported under the app.module.ts , here is my routing module: app-routing.module.ts import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { LoginComponent } from './login/login.component'; import { WelcomeComponent } from './welcome/welcome.component'; import { CustomersListComponent } from './customer/customers-list/customers-list.component'; import { CustomerDetailComponent } from './customer/customer-detail/customer-detail

Angular 2 and jQuery - how to test?

走远了吗. 提交于 2019-12-05 12:03:34
问题 I am using Angular-CLI (webpack version) for my Angular 2 project and I also need to use jQuery (sadly. In my case, it's a dependency of Semantic-UI and I am using it for handling menu dropdowns). The way I am using it: npm install jquery --save Then listing in it angular-cli.json file in the scripts array: scripts": [ "../node_modules/jquery/dist/jquery.min.js" ] So it gets included into bundle file and this file is automatically used to root html file: <script type="text/javascript" src=

On console.log, ViewChild variable is undefined in unit test

╄→尐↘猪︶ㄣ 提交于 2019-12-05 07:59:57
I'm trying to test a component that has an @ViewChild annotation. One of the functions that I'm trying to test calls the @ViewChild 's element for focus. However, when I try to log out the @ViewChild variable, it is always undefined . I thought componentFixture.detectChanges() would initiate the ElementRef , but it doesn't seem to. Is there any way to make it so it isn't undefined ? I don't know which version of Angular2 you use and how you initialize your test suite but the detectChanges method on the ComponentFixture instance is responsible to set such fields. Here is a sample test that

Karma and RequireJS getting files outside base url

不想你离开。 提交于 2019-12-05 07:08:16
I am trying to configure automatic testing using karma. My file structure is as follows /assests /css /font /img /js /collection /lib /model /plugin /spec /view test-main.js main.js /templates index.html karma.conf.js karma.conf.js: module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine', 'requirejs'], // list of files / patterns to load in the browser files: [ 'js/test-main.js', {pattern: 'js/*.js

How to test the config function of an Angular module?

老子叫甜甜 提交于 2019-12-05 03:45:56
I'm defining some setup code in the config function of an Angular module that I want to unit test. It is unclear to me how I should do this. Below is a simplified testcase that shows how I'm getting stuck: 'use strict'; angular.module('myModule', []).config(['$http', '$log', function($http, $log) { $http.get('/api/getkey').then(function success(response) { $log.log(response.data); }); }]); describe('myModule', function() { it('logs a key obtained from XHR', inject(function($httpBackend) { $httpBackend.expectGET('/api/getkey').respond(200, '12345'); angular.module('myModule'); $httpBackend

Unable to find a suitable version for angular with bower installation error for angular-animate module

家住魔仙堡 提交于 2019-12-05 03:16:10
I am using Angular 1.2.6 . I am trying to use bower to install angular-animate and ngAnimate-animate.css . I've tried installing ( bower install --save angular-animate ), uninstalling several time and diff code on github from 1.2.16 and 1.2.17. Bower keeps wanting to install the older version of angular-animate 1.2.16 compatible with Angular 2.1.12 . All of my passing karma unit tests fail after installing angular-animate as well. I keep on getting this error. Any ideas why? bower angular-animate#* cached git://github.com/angular/bower-angular-animate.git#1.2.16 bower angular-animate#*

Angular mock fails to inject my module dependencies

扶醉桌前 提交于 2019-12-05 01:56:01
I want to test an Angular controller for my application fooApp , defined as follow: var fooApp = angular.module('fooApp', [ 'ngRoute', 'ngAnimate', 'hmTouchEvents' ]); ... The controller, MainCtrl is defined: "use strict"; fooApp.controller('MainCtrl', function ($scope, $rootScope, fooService) { ... } So I've tested several ways to create a test, like this one: 'use strict'; describe('MainController test', function () { var scope; var controller; beforeEach(function () { angular.mock.module('ngRoute', []); angular.mock.module('ngAnimate', []); angular.mock.module('hmTouchEvents', []); angular

How to test a directive's controller using angularJS-karma-jasmine?

随声附和 提交于 2019-12-05 01:40:30
问题 Goal: Write a passing test for the waCarousel directive scope variable: self.awesomeThings . Expect this test pass when self.awsomeThings.length.toBe(3) to is true? Question: How can I properly write this test? rather how do I inject a directives controller? Directive: angular.module('carouselApp') .directive('waCarousel', function() { return { templateUrl: '../../../views/carousel/wa.carousel.html', controller: function($scope) { var self = this; self.awesomeThings = [1, 2, 3]; return $scope

How to run a single test file with Karma/Jasmine?

本小妞迷上赌 提交于 2019-12-05 01:03:40
I'm using Karma and Jasmine for testing my Angular JS code. I managed to run all the tests in my project using Karma, but if I try to run just a single file I'm getting the following error: ReferenceError: describe is not defined . Is it possible to run just a single test file and if yes then how? P.S. I'm using Intellij IDEA. Pieter Willaert Although it's not ideal, you can replace describe (and it ) with fdescribe (and fit ) so only those tests will be executed On the other hand, xdescribe / xit excludes the tests from your suite If you use Gulp, you can combine gulp-karma & yargs to pass in