karma-jasmine

Running unit test for angular app on tfs server

久未见 提交于 2019-12-24 18:44:48
问题 I am running unit test for angular app using karma and jasmine. Since karma pops up browser window, In my build definition (of tfs) to run unit test, the build gets stuck up! How to ensure it doesn't pop up a window .Instead of popping up the results in a browser window, I want the results to be written into a file (to be specific to Junit report coverage in xml format , such that TFS server understands the file and generates report) 来源: https://stackoverflow.com/questions/55708279/running

Testing HTTP with mockbackends

不羁的心 提交于 2019-12-24 15:30:41
问题 I'm working on building out tests for my services in Angular 2. Building out the mock backends is proving to be a real trial. I have been able to test the services with it making actual HTTP requests successfully but I would like to keep these segregated from the third part. I've combed through the two main articles I have been able to find (first, second as well as the angular docs. When I was making successful http requests to actual third party services, I had to use done(); to ensure that

WebStorm - Jasmine jQuery

大兔子大兔子 提交于 2019-12-24 14:08:23
问题 I'm quite new to the usage of WebStorm, but it's not working as epected. I had a project in the past, but now I try to recreate it and try to unit test my code. I'm very new to unit testing JavaScript code. So, I have a file karma.conf.js which contains the following: module.exports = function(config){ config.set({ basePath : './', files : [ '../../Resources/External/Bower/angular/angular.js', '../../Resources/External/Bower/angular-mocks/angular-mocks.js', '../../Resources/Scripts/OfficeUI

Tracing errors using karma + babel + webpack with bundles

牧云@^-^@ 提交于 2019-12-24 13:05:46
问题 Using karma + babel + webpack to run ES6 unit tests. I use a webpack bundle to locate and transpile the ES6. It all works, but whenever there is an error in any test file I get messages with no indication where the error originated, like Uncaught TypeError: Cannot read property 'querySelector' of null at /pth/to/test.bundle.js:13256 It's always /pth/to/test.bundle.js:xxxx . Any idea how to make it show more useful messages? Here's my config module.exports = function(config) { config.set({

Why won't $location.path trigger a $routeChangeStart in the controller?

巧了我就是萌 提交于 2019-12-24 11:33:57
问题 My test has: it("should clear the search field when the URL changes", function() { createController(); $scope.init(); $scope.searchTerm = 'some term'; $location.path('/source'); $rootScope.$apply(); expect($scope.searchTerm).toBe(''); }); My controller is: angularMoonApp.controller('SearchController', ['$scope', '$location', function ($scope, $location) { $scope.init = function() { $scope.$on('$routeChangeStart', function(next, current) { $scope.searchTerm = ''; }); } $scope.init(); }]);

Testing a controller not using $scope using karma

試著忘記壹切 提交于 2019-12-24 11:28:13
问题 I followed the instructions on docs.angularjs.org to test a controller with karma and it's perfectly working. However I was wondering if it's possible to test a controller which is not using $scope? Testing this controller is ok: angular.module('starter.controllers') .controller('PasswordController', function PasswordController($scope) { $scope.password = ''; $scope.grade = function() { var size = $scope.password.length; if (size > 8) { $scope.strength = 'strong'; } else if (size > 3) {

Angular2 tests and RESOURCE_CACHE_PROVIDER global

怎甘沉沦 提交于 2019-12-24 10:58:25
问题 I'm looking a way to set provider RESOURCE_CACHE_PROVIDER as ResourceLoader on initTest phase on karma-test-shim.src.js We cannot modify single test because we use them also on dist folder where templateUrl is replace with template by gulp-inline-ng2-template Here some tests we have already run without success: Promise.all([ System.import("@angular/core/testing"), System.import("@angular/platform-browser-dynamic"), System.import("@angular/platform-browser-dynamic/testing") ]).then(function (

Jasmine Karma Error “An error was thrown in afterAll\nUncaught ReferenceError: container is not defined thrown”

江枫思渺然 提交于 2019-12-24 08:37:22
问题 I keep getting an error when running jasmine tests via karma test runner, which reads like this: { "message": "An error was thrown in afterAll\nUncaught ReferenceError: container is not defined thrown", "str": "An error was thrown in afterAll\nUncaught ReferenceError: container is not defined thrown" } My package.json is as follows: { "name": "3dm", "version": "1.0.0", "description": "3dm", "main": "src/index.html", "dependencies": { "three-obj-loader": "^1.1.3", "three.js": "*" },

Why does my jasmine tests fail on this directive?

半腔热情 提交于 2019-12-24 08:16:17
问题 I have built an angular directive onInputChange that should fire a callback when the users changes a value of an input by either clicking outside of the input (blur) or hitting ENTER . The directive can be used like: <input type="number" ng-model="model" on-input-change="callback()"/> It uses the following code: app.directive('onInputChange', [ "$parse", function ($parse) { return { restrict : "A", require : "ngModel", link : function ($scope, $element, $attrs) { // var dirName =

Angular6 Jasmine TypeError: expect(…).toBeVisible is not a function

霸气de小男生 提交于 2019-12-24 05:07:05
问题 Setting up jasmine-query-matches in angular6 On angular 5 project it looks at simple as import { } from 'jasmine-jquery/lib/jasmine-jquery'; import { } from 'jasmine-jquery-matchers'; import * as $ from 'jquery'; On angular 6 i have tried the following import {} from "jasmine-jquery/lib/jasmine-jquery" ; import {} from "jasmine-jquery-matchers/dist/jasmine-jquery-matchers" ; import { } from "karma-jasmine-jquery"; import * as $ from 'jquery'; OR import {} from "jasmine-jquery" ; import {}