karma-jasmine

Angular testing: “Illegal state: Could not load the summary for directive” for an empty component

和自甴很熟 提交于 2019-12-07 13:11:19
问题 None of my components were passing unit tests, so I made a new one in the project to try and diagnose. import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-thing', templateUrl: './thing.component.html', styleUrls: ['./thing.component.scss'] }) export class ThingComponent implements OnInit { constructor() { } ngOnInit() { } } And a thing.component.spec.ts file as follows describe('ThingComponent', () => { let component: ThingComponent; let fixture: ComponentFixture

Jasmine Tests give error “Uncaught ReferenceError: require is not defined”

落花浮王杯 提交于 2019-12-07 11:38:47
问题 I am trying to run Jasmine tests with Karma on my React site. My tests were working before, and I'm not sure what has changed, but now I get the error: Uncaught ReferenceError: require is not defined for Chrome and PhantomJS and Firefox give me similar errors. Please let me know if more info would be helpful. I have found a lot of similar questions on the web, but nothing that fixes the problem. You can see the test file below and the full project is on my github repo. Thanks in advance! My

Jasmine: Unit test http service error observable

柔情痞子 提交于 2019-12-07 08:45:56
问题 I am pretty confused on how to mock that my http service catches an observable error. I have read through the angular documentation but I do not understand how I would structure the test. I would like to mock an error in my service, then check that it catches an error observable. I have another service that creates and throws the error observable. The rest of my services just catch it when encountering an error. I am honestly very confused on how to implement this. Here is a simple verison of

Karma + jasmine + angular + ui router - testing for resolve with state.go with params

血红的双手。 提交于 2019-12-07 08:10:21
问题 I have state defined in my angular module "moduleB" as follows $stateProvider .state('stateB', { parent: 'stateA', abstract: true, templateUrl : baseUrl+'/templates/stateB.html' }) .state('stateB.details', { url: '/stateB/details/:param1/:param2', resolve : { value3 : ['$localStorage', '$stateParams', function($localStorage, $stateParams){ return $localStorage.value3[$stateParams.param1]; }] }, views : { 'view1' : { templateUrl : baseUrl+'/templates/view1.html', controller: 'View1Ctrl' },

Karma with Webpack and Typescript performs no tests

℡╲_俬逩灬. 提交于 2019-12-07 04:20:51
问题 I'm trying to figure out how to use the Karma testrunner with Webpack and Typescript source files. Taking this source file as the only test file as an example: test.spec.ts var message: string = 'yay'; alert(message); describe('1st tests', () => { it('true is true', () => expect(true).toBe(true)); }); And the following karma config: karma.config.js module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], plugins: [ require('karma-jasmine'), require('karma

angular2: how to test a component which has an observable time interval

天大地大妈咪最大 提交于 2019-12-07 04:00:35
问题 I have a slide-show component that has an Input array of slide objects and shows each one as long as it's been defined in slide.time of itself. also there are two buttons that clicking them has to slide to the next item and reset the timer. in order to make this work, I'm using Observables like this: /** * a "SUBJECT" for pausing(restarting) the slider's auto-slide on user's click on left and right arrows * @type {Subject} */ private pauser = new Subject(); /** * the main observable for timer

Angular Testing: FormControl valueChanges Observable

僤鯓⒐⒋嵵緔 提交于 2019-12-07 03:10:22
问题 I have a text input and I'm listening for the changes. component name = new FormControl('',Validators.required); ngOnInit() { this.data = 'oldvalue'; this.checkName(); } checkName() { this.name.valueChanges.subscribe(val=>{ console.log(val); this.data= "newvalue"; // updating Value }); } HTML <input name="name" formControlName="name"> My Attempt so far: component.spec.ts it('should test data field ', () => { const fixture = TestBed.createComponent(UserComponent); const app=fixture

Karma and RequireJS getting files outside base url

可紊 提交于 2019-12-07 02:11:45
问题 I am trying to configure automatic testing using karma. My file structure is as follows /assests /css /font /img /js /collection /lib /model /plugin /spec /view test-main.js main.js /templates index.html karma.conf.js karma.conf.js: module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine',

On console.log, ViewChild variable is undefined in unit test

佐手、 提交于 2019-12-07 02:05:29
问题 I'm trying to test a component that has an @ViewChild annotation. One of the functions that I'm trying to test calls the @ViewChild 's element for focus. However, when I try to log out the @ViewChild variable, it is always undefined . I thought componentFixture.detectChanges() would initiate the ElementRef , but it doesn't seem to. Is there any way to make it so it isn't undefined ? 回答1: I don't know which version of Angular2 you use and how you initialize your test suite but the

Unable to find a suitable version for angular with bower installation error for angular-animate module

感情迁移 提交于 2019-12-06 22:40:18
问题 I am using Angular 1.2.6 . I am trying to use bower to install angular-animate and ngAnimate-animate.css. I've tried installing ( bower install --save angular-animate ), uninstalling several time and diff code on github from 1.2.16 and 1.2.17. Bower keeps wanting to install the older version of angular-animate 1.2.16 compatible with Angular 2.1.12 . All of my passing karma unit tests fail after installing angular-animate as well. I keep on getting this error. Any ideas why? bower angular