karma-jasmine

How to include PHP file to run test in Karma/Jasmine?

蓝咒 提交于 2019-12-12 03:08:55
问题 The JS file I want to test is useless without PHP app on top of which it executes, because backend of my app generates all the DOM elements and data, which my JS app utilizes. In other words, If I write in my.conf.js : files: [ 'app.js', 'spec/test.js' ], app.js will throw tons of errors regarding not found elements, like tables, graph containers, etc. Because of that I need to include my whole app to the test somehow. Perhaps by including my app's main index.php ? Is it possible in Karma

Return a promise in jasmine directive controller

丶灬走出姿态 提交于 2019-12-12 03:02:27
问题 In my unit test i need to return a promise so that my tests don't fail: describe('refugeeRegister', function () { var controller, scope, rootScope, window; beforeEach(function () { module('refugeeHire'); module("templates"); module('refugeeHire.components.refugee_register', function ($provide) { $provide.service("authenticationService", function () { this.signup = jasmine.createSpy("signup").and.returnValue(); this.getCookie=jasmine.createSpy("getCookie"); }); }); }); beforeEach(inject

Don't work $compile in Jasmine Karma Angular

家住魔仙堡 提交于 2019-12-12 02:52:09
问题 (function () { 'use strict'; angular .module('app.widgets') .directive('analiticsHere', analitics); function analitics() { var directive = { template: '<div>hello world</div>' }; return directive; } })(); Create simple directive. Ant try to test it. inject(function($compile, $rootScope, $templateCache){ compile = $compile; scope = $rootScope.$new(); template = $templateCache.get('scripts/widgets/templates/Analytics.html'); console.log(template);//return nothing var element = angular.element('

Can't install Karma-PhantomJs and Karma-Jasmine

笑着哭i 提交于 2019-12-12 02:16:56
问题 I am trying to create test for my app and am attempting to set up my karma.conf.js correctly. This file is karma.conf.js // Karma configuration // http://karma-runner.github.io/0.12/config/configuration-file.html // Generated on 2015-07-12 using // generator-karma 1.0.0 module.exports = function(config) { 'use strict'; config.set({ // enable / disable watching file and executing tests whenever any file changes autoWatch: true, // base path, that will be used to resolve files and exclude

Angular 2 - Issues running Component tests

自古美人都是妖i 提交于 2019-12-12 01:42:34
问题 I am trying to run a component test for Angular 2 - rc5 and am getting the following error when I run the tests: Missing error handler on socket . TypeError: (msg || "").replace is not a function at /project/node_modules/karma/lib/reporter.js:48:23 I concluded that when I comment out the setBaseProviders line (and the lines in the component tests that might make use of these providers) the rest of the test suite runs without issues. Unfortunately, it appears I need these providers in order to

spyOn not working in Http Interceptor in Angular 6

江枫思渺然 提交于 2019-12-12 00:07:35
问题 I am trying to test HttpInterceptor that logs the response of the http request. I have a log service that logs the response of the request. The interceptor logs only for GET requeststs. Here's my interceptor: import { HttpInterceptor, HttpHandler, HttpEvent, HttpRequest, HttpResponse } from '@angular/common/http'; import { Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; import { LogService } from './log.service'; import { Injectable } from '@angular/core'; @Injectable(

Can TestComponentBuilder test an angular component within a component?

本小妞迷上赌 提交于 2019-12-11 23:33:19
问题 So, I'm trying to write a unit test for my component. My component is a dynamically created list, and when a user clicks certain items, I'd like my test to validate that the component generates outputs correctly. To test this, I wrote a demo component that creates my component within its template, and then attempted to get TestComponentBuilder to create this demo component and click items on the lists. Unfortunately, my unit test cases can't find my component's html elements to click them. I

Karma jasmine and angular controller using 'Controller as' syntax (this instead of $scope)

和自甴很熟 提交于 2019-12-11 22:44:14
问题 I'm trying to set up karma to make some unit tests but I can't manage to make it work on a basic example : This is the controller file : angular.module('balrogApp.requests', [ /* Dependancies */ ]) // Routes configuration .config(['$routeProvider', function($routeProvider) { /* $routeProvider configuration */ }]) .controller('requestsController', function(Requests, Users, Projects, RequestsComments, CostEstimations, Regions, growl, $route, $rootScope, $scope, $location) { this.test = 'test42'

Angular Jasmine FormControl Unit Test valueChanges

冷暖自知 提交于 2019-12-11 19:36:16
问题 I want to unit test my following method: this.boxValue = ''; subscribeToFilterChanges(): void { this.filterBox.valueChanges .subscribe( data => { if (data) { this.boxValue = data.trim().toLowerCase(); } } ); } filterBox is a FormControl: filterBox = new FormControl(''); HTML is: <mat-form-field appearance="standard"> <input matInput [formControl]="filterBox" id="filterBox-input"> </mat-form-field> I've written the unit test as: it('verify filter changes', () => { let filterBoxInput = fixture

why “[web-server]: 404: /absoluteC” when running karma

跟風遠走 提交于 2019-12-11 17:36:27
问题 I found several similar question but none of the suggestions fixed my issue. Basically they are suggesting add some dependency (I am using only native webcomponents so it doesn't appliy to my case) or check the path. I checked carefully and the path is 100% correct. I found a bit strange that the warnning message shows absolute before the real path. BTW, the path is really coorect. Whole code github Karma.conf.js module.exports = function(config) { config.set({ frameworks: ["jasmine"], files: