karma-jasmine

Unit Testing angular2 component with imported module

房东的猫 提交于 2019-12-21 03:59:18
问题 I am trying to write a test on a component which uses angular-material2, but when I add it to my testModule declarations I get: Error: Template parse errors: 'md-card-title' is not a known element: 1. If 'md-card-title' is an Angular component, then verify that it is part of this module. 2. If 'md-card-title' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. Adding MaterialModule to the declarations throws `Error:

Conditionally ignore individual tests with Karma / Jasmine

≯℡__Kan透↙ 提交于 2019-12-20 17:25:04
问题 I have some tests that fail in PhantomJS but not other browsers. I'd like these tests to be ignored when run with PhantomJS in my watch task (so new browser windows don't take focus and perf is a bit faster), but in my standard test task and my CI pipeline, I want all the tests to run in Chrome, Firefox, etc... I've considered a file-naming convention like foo.spec.dont-use-phantom.js and excluding those in my Karma config, but this means that I will have to separate out the individual tests

How to get better test reports in the console?

北慕城南 提交于 2019-12-20 16:11:25
问题 I have a fairly simple karma.config.js file basePath = '../'; files = [ JASMINE, JASMINE_ADAPTER, 'js/lib/angular*.js', 'test/lib/angular/angular-mocks.js', 'js/**/*.js', 'test/unit/**/*.js' ]; autoWatch = true; browsers = ['PhantomJS']; When I run karma start config/karma.conf.js --single-run I'm getting the following output $ karma start config/karma.conf.js --single-run [2013-06-24 23:47:08.750] [DEBUG] config - autoWatch set to false, because of singleRun INFO [karma]: Karma server

Some of your tests did a full page reload - error when running Jasmine tests

心已入冬 提交于 2019-12-20 10:21:50
问题 I'm running into an issue where when I run my tests on Jasmine, I get this error below. The problem is, it seems to happen when I try to execute a certain amount of tests. It doesn't seem to be tied to a particular test, as if I comment out some, the tests pass. If I uncomment some tests, the error appears. If I comment out ones that were uncommented before, they all pass again. (ie if I have red, green, blue and orange test and it fails, I comment out orange and blue it passes, then I

what is the real difference between ng test and ng e2e

江枫思渺然 提交于 2019-12-20 08:48:11
问题 I am afraid someone close my question but I couldn't find a satisfying question (maybe because I am very limited in Angular 2+ world and I understood something wrong). As far as I could understand after few Hello World done and few YouTube demo watched: ng test: you write your test using Jasmine language you test your test with many Browsers available using Karma you execute either unit or integrated testing all xxx.compnent.spec.ts run and a final report similar to JUnit is showed in browser

AngularJS : Testing factory that returns $http promises

妖精的绣舞 提交于 2019-12-20 05:13:49
问题 Trying to test an angular service that returns an $http GET request and the then handler, but I'm not able to test that the logic actually works inside of the then function. Here is a basic, truncated version of the service code: angular.module('app').factory('User', function ($http) { var User = {}; User.get = function(id) { return $http.get('/api/users/' + id).then(function (response) { var user = response.data; user.customProperty = true; return user; }); }; return User; }); And here is

How to exclude Folder (components) for unit testing in Angular 4 using Karma config?

拟墨画扇 提交于 2019-12-20 01:54:06
问题 I am using angular cli version 1.4.5 and below is the karma.conf.ts file module.exports = function (config) { config.set({ basePath: '', exclude: [ "src/app/components/panel/panel.component.spec.ts", "src/app/components/accordion/accordion.component.spec.ts" ], frameworks: ['jasmine', '@angular/cli'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('@angular/cli/plugins/karma')

Angular mock $httpBackend give No pending request to flush

我与影子孤独终老i 提交于 2019-12-19 12:25:10
问题 Following the official guide at angularJS $httpBackend I'll do this test, but Karma give me this error : Error: No pending request to flush ! at Function.$httpBackend.flush Test 'use strict'; describe('profileCtrl', function () { var scope, $httpBackend; beforeEach(angular.mock.module('maap')); beforeEach(angular.mock.inject(function($rootScope, $controller, _$httpBackend_){ $httpBackend = _$httpBackend_; $httpBackend.when('GET', 'profile').respond([{id: 1, name: 'Bob'}]); scope = $rootScope.

Karma error when running angular2 tests via jenkins on linux

风流意气都作罢 提交于 2019-12-19 02:32:47
问题 I am seeing the following error when running my angular2 unit tests using karma with jenkins. My tests run fine when I run them on my local machine (windows), however when running the test via jenkins on linux I get the following error. Missing error handler on `socket`. TypeError: (msg || "").replace is not a function at /home/hudson/.hudson/jobs/workspace/pjt/node_modules/karma/lib/reporter.js:45:23 My tests are never started any ideas what could be causing this. I took a look at the karma

Found the synthetic property @enterAnimation. Please include either “BrowserAnimationsModule” or “NoopAnimationsModule” in your application. Angular4

邮差的信 提交于 2019-12-18 13:52:30
问题 When running Karma to test my Angular4 application, I get this error Found the synthetic property @enterAnimation. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. though I already imported the module in app.module.ts // animation module import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; ... @NgModule({ imports: [... BrowserAnimationsModule, ... ], and in my component : import { Component, OnInit } from '@angular/core'