karma-jasmine

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

ぐ巨炮叔叔 提交于 2019-12-06 19:43:31
问题 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. 回答1: 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

Unit test when a button is enabled using Karma in Angular2

被刻印的时光 ゝ 提交于 2019-12-06 19:26:22
问题 I have an Angular2 project setup using angular CLI. I'm trying to test a form component. It has two fields: email and password. Both are required . There's a login button of the type submit . It's enabled only after the user has provided valid inputs in both the fields. <form (ngSubmit)="login()" #loginForm="ngForm"> <md-input-container class="md-block"> <input md-input [(ngModel)]="user.email" class="userEmail" name="userEmail" type="email" placeholder="Email" ngControl="userEmail" required>

Angular2 Quickstart Tutorial Breaking Karma Tests - “Can't bind to 'ngModel' since it isn't a known property of 'input'.”

≯℡__Kan透↙ 提交于 2019-12-06 17:00:49
问题 I am following the official Angular "Hero" Quickstart Tutorial whilst trying to TDD it. https://angular.io/docs/ts/latest/tutorial/toh-pt1.html As soon as I get to the step to replace: <input value="{{hero.name}}" placeholder="name"> with <input [(ngModel)]="hero.name" placeholder="name"> my Karma test runner throws the following error: Error: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'. (" name: ][(ngModel)]="hero.name" placeholder="name"> "):

How to test angular 2 component with nested components inside with their own dependencies ? (TestBed.configureTestingModule)

℡╲_俬逩灬. 提交于 2019-12-06 16:44:44
问题 I have a component A that use a component B,c,D in its template: ###template-compA.html <comp-b></comp-b> <comp-c [myinput]="obj.myinput"></comp-c> <comp-d ></comp-d> ...etc To simplify, let's say their is only one directive in component A: ###template-compA.html <comp-b></comp-b> My comp-b has its own dependencies (services or other comp). If I want to test comp-a this way: TestBed.configureTestingModule({ declarations: [comp-A], imports: [ReactiveFormsModule], }).overrideComponent

sorting feature in ngTable using Jasmine Testing

帅比萌擦擦* 提交于 2019-12-06 12:08:45
问题 I have created an application using ng-table , the application is working fine but i don'nt know how to write a test case for that sorting and getData. Can anyone please tell me some solution for testing that functionality My code is as given below jasmine test case describe('Testing Controllers', function() { describe('Testing WorkController Controller', function() { var WorkController, $scope; beforeEach(module('wsd')); beforeEach(inject(function($controller, $rootScope) { $scope =

How to test angular app with John Papa style, Karma, and Jasmine with data service?

北慕城南 提交于 2019-12-06 11:24:18
For some reason, even following the example provided by Josh in the post reply How to test John papa vm.model unit testing with jasmine? , I can't get my controller's values to show up in the testing area. I think it's because of the data service, but it is a necessary component for our SPA, as is using John Papa's styling . Below is a code snippet to hold the code and display the errors I'm receiving. (function() { 'use strict'; angular.module('tickets') .service("DataService", DataService) /* @ngInject */ DataService.$inject = ["$rootScope", "$q"]; function DataService($rootScope, $q) { var

How to karma test .config where $httpProvider is used in a service layer?

冷暖自知 提交于 2019-12-06 10:27:51
问题 This is how my service looks like (function(){ 'use strict'; angular.module('gls.service', []) .config(config) .service('popup', popup) .service('API', api); /* Config */ config.$inject = ['$httpProvider']; function config($httpProvider) { delete $httpProvider.defaults.headers.common['X-Requested-With']; $httpProvider.defaults.headers.get = { 'Content-Type': 'application/json' }; $httpProvider.defaults.headers.post = { 'Content-Type': 'application/json' }; $httpProvider.defaults.headers.put =

Unit Test Expect SpyOn Not Found

五迷三道 提交于 2019-12-06 09:57:55
I have a directive (restrict A) that handles an event click, and calls a service based on a value. Directive: define(function () { 'use strict'; var myDirective = function ($rootScope, myFactory) { return { restrict: 'A', scope: { _myValue : '=value' }, link: function(scope, element, attrs) { element.bind('click', function() { if (scope._myValue === 'red') { myFactory.red(); } if (scope._myValue === 'green') { myFactory.green(); } if (scope._myValue === 'black') { myFactory.black(); } }); } }; }; return ['$rootScope', 'myFactory', myDirective]; }); Test: define(['angular-mocks'], function () {

Jasmine unit test for angular service In controller

可紊 提交于 2019-12-06 08:28:52
I'm new to jasmine framework. I've gone through some tutorials and learned and started writing unit tests. 'facing one issue here is the description. I have a controller where i can invoke a service call to get the data. See the code below. $scope.getEmpInfo = function() { EmpService.getInfo($scope.empid) .then(function(data) { $scope.empData = data; $scope.populateEmpData($scope.empData); }, function(reason) { //do nothing } } Now, i want to write a unit test for the above method. Im able to make a spy on serice using promise but i wasnt able to spy $scope.populateEmpData() . here is my test

Angular Unit test fails when i try to inject a service

醉酒当歌 提交于 2019-12-06 05:47:45
I have a angular where i want to test my controllers and services with karma and jasmine. I wrote some tests and they worked. Then i did some big changes to my angular project. Now my tests are all failing and i can't figure out why. I commented everything out in my tests and just wanted to check if the $controller service gets loaded. But not even this works. My module definition: angular.module('cManagement', [ 'angular-multi-select', 'ngCookies', 'ui.router', 'ui.bootstrap', 'pascalprecht.translate', 'ngIdle' ]) Here is my test: use strict'; describe("cManagement", function() { beforeEach