karma-jasmine

Unit test when a button is enabled using Karma in Angular2

限于喜欢 提交于 2019-12-05 00:43:08
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> </md-input-container> <br> <md-input-container class="md-block"> <input md-input [(ngModel)]="user

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

旧城冷巷雨未停 提交于 2019-12-04 22:34:53
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"> "): AppComponent@6:23 Expected undefined to be defined. However, the application works as expected and I see

Branches on constructor not covered

一笑奈何 提交于 2019-12-04 19:13:08
问题 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,

Error: Please call “TestBed.compileComponents” before your test

时间秒杀一切 提交于 2019-12-04 19:12:05
问题 I'm getting this error: Error: This test module uses the component MessagesComponent which is using a "templateUrl", but they were never compiled. Please call "TestBed.compileComponents" before your test. When trying to run this simple test Angular 2 & Jasmine Test: let comp: MessagesComponent; let fixture: ComponentFixture<MessagesComponent>; describe('MessagesComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ MessagesComponent ], providers: [ {provide:

console.log not working on any karma project

房东的猫 提交于 2019-12-04 18:48:24
问题 UPDATE: tl;dr; I updated my npm packages and couldn't see any console.log output anymore in karma. Looks like it's b/c of a behavior change that only shows console.log output at the LOG_DEBUG level and hides it at LOG_INFO . When was that change made and is there a way to revert it? ORIGINAL: When I run karma from a windows command prompt I cannot see the output of console.log . I used to see it fine in many projects, but now it's suddenly not working in any of my projects. This seems to have

sorting feature in ngTable using Jasmine Testing

纵饮孤独 提交于 2019-12-04 17:47:46
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 = $rootScope.$new(); WorkController = $controller('WorkController', { $rootScope: $rootScope, $scope: $scope,

Jasmine test to test if the controller is defined

做~自己de王妃 提交于 2019-12-04 16:47:17
New to Jasmine tests for angular. I am trying to test if the controller I defined is defined or not to begin with but I am getting error saying Expected undefined to be defined. Here is my main code: // controller logic MatchController.js (function () { 'use strict'; angular.module('app.match') .controller('MatchController', MatchController); MatchController.$inject = ['APP_CONFIG', '$authUser', '$http', '$rootScope', '$state', '$stateParams', 'SearchService', 'ConfirmMatchService', 'MusicOpsService', 'ContentOpsService', 'MatchstickService', 'MatchService', 'Restangular']; function

AngularJS Jasmine Test Fails: Failed to instantiate module

梦想的初衷 提交于 2019-12-04 16:37:55
问题 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 (

TypeError: undefined is not a constructor

為{幸葍}努か 提交于 2019-12-04 16:13:22
问题 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(

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

浪尽此生 提交于 2019-12-04 16:10: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 = { 'Content-Type': 'application/json' }; } followed by the functions for popup and API services. How to