karma-jasmine

Karma cannot load Angular 2 Component

送分小仙女□ 提交于 2019-12-23 03:25:08
问题 My Karma cannont load angular 2 component. Drop this error: [web-server] :404 : /base/src/client/app/container/container.component i do everything with angular 2 testing tutorial (i only modified path in karma) So problem must be in path. but i don't have any idea how to fix it. My Path: src | |client | | |container | | | |container.component.ts | | | |container.component.spec.ts |karma.conf.js |karma-test-shim.js container.component.ts import { Component, OnInit } from '@angular/core';

Angular2 testing with fakeAsync

风流意气都作罢 提交于 2019-12-22 19:00:31
问题 I'm trying to use fakeAsync to test an Angular 2 component, but the fixture variable is not being set. In fact, the promise callback is not being called. Here is the code: @Component({ template: '', directives: [GroupBox, GroupBoxHeader] }) class TestComponent { expandedCallback() { this.expandedCalled = true; } } it('testing...', inject([TestComponentBuilder], fakeAsync((tcb) => { var fixture; tcb.createAsync(TestComponent).then((rootFixture) => { fixture = rootFixture }); tick(); fixture

Karma-Jasmine: How to test $translate.use?

无人久伴 提交于 2019-12-22 17:49:15
问题 THE SITUATION: I am testing the function that allow the user to select a language. But I am getting the following error: TypeError: $translate.use is not a function I have seen similar questions in SO and other forums but they are not working for me. THE CODE: The configuration: app.config(function($stateProvider, $urlRouterProvider, $translateProvider) { $translateProvider.useSanitizeValueStrategy('sanitize'); $translateProvider.translations('EN', { "MY_ACCOUNT": "My account", "PROJECT_LIST"

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

橙三吉。 提交于 2019-12-22 13:06:30
问题 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) /*

Flushing successful mock POST request using Jasmine does not execute the AngularJS success function

痴心易碎 提交于 2019-12-22 10:08:10
问题 This is my AngularJS post.js : angular.module("PostPageApp", ["BaseApp"]) .controller("MainCtrl", ["$http", "$window", "BaseService", function($http, $window, BaseService) { var self = this; self.add = function() { BaseService.add.post(self.post, function() { self.cerrorMessages = BaseService.cerrorMessages; }); }; }]); This is base.js : angular.module("BaseApp", []) .config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.xsrfCookieName = 'csrftoken'; $httpProvider.defaults

Jasmine tests pass in Chrome and Firefox but fail with PhantomJS

隐身守侯 提交于 2019-12-22 05:51:13
问题 I am building a basic blogging app with React. I am using Jasmine and Karma to run my front end tests. I got my first test up and running and it passes in Chrome (Chromium) and Firefox, but when it runs in PhantomJS I get the following error: PhantomJS 1.9.8 (Linux 0.0.0) ERROR TypeError: 'undefined' is not a function (evaluating 'ReactElementValidator.createElement.bind( null, type )') at /home/michael/repository/short-stories/test/karma_tests/story_test.js:1742 My test file looks like this:

Issue getting Karma 1.1.0 and Angular 2 tests working

时光总嘲笑我的痴心妄想 提交于 2019-12-22 05:26:04
问题 I use Karma 1.1.0. Here is my karma.shim: 'use strict'; // Tun on full stack traces in errors to help debugging Error.stackTraceLimit = Infinity; jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; // // Cancel Karma's synchronous start, // // we will call `__karma__.start()` later, once all the specs are loaded. __karma__.loaded = function() {}; var map = { 'app': 'base/app', 'rxjs': 'base/node_modules/rxjs', '@angular': 'base/node_modules/@angular' }; // packages tells the System loader how to load

Error: [$injector:nomod] Module 'ui.bootstrap' is not available! while Karma run in webstorm

北慕城南 提交于 2019-12-22 04:43:12
问题 Hi I'm getting the following error in webstorm while running karma test run Error: [$injector:nomod] Module 'ui.bootstrap', 'ui.unique' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. i looked in the internet and they said to check dependency file ui.bootstrap might be missed like that. but the application works fine and while testing only it shows this error in my karma.conf

Lifecycle hook of AfterViewInit in Jasmine test

假装没事ソ 提交于 2019-12-22 03:27:04
问题 I am confused on lifecycle hooks in relationship with Jasmine testing. The LifeCycle Angular doc does not mention testing https://angular.io/guide/lifecycle-hooks. The testing doc only mentions OnChange https://angular.io/guide/testing. I have a sample component as follows: import { Component, OnInit, AfterViewInit, OnDestroy, ElementRef } from '@angular/core'; ... @Component({ selector: 'app-prod-category-detail', templateUrl: './prod-category-detail.component.html', styleUrls: ['./prod

Jasmine test to test if the controller is defined

有些话、适合烂在心里 提交于 2019-12-21 21:07:19
问题 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',