karma-jasmine

Angular testing submit event on reactive form

一曲冷凌霜 提交于 2019-12-04 15:03:30
问题 Context I have a component with a basic form (reactive form). I try to test the submit event on this form to see if it calls the necessary method properly. My problem I can't trigger the submit event of the form Files Component.html <form class="form-horizontal" id="staticForm" [formGroup]="mySimpleForm" (ngSubmit)="sendMethod();" > <input type="text" formGroupName="email"> <button type="submit">Send form</button> </form> Component.ts ngOnInit() { this.initSimpleForm(); } private

Cannot make XHRs from within a fake async test

烈酒焚心 提交于 2019-12-04 14:32:50
Total novice at Karma/Jasmine looking for some assistance. I'm trying to run the following test and I get the error "Cannot make XHRs within a fake async test". I have included the test and the method I am attempting to call. Any help is greatly appreciated. import... fdescribe('CageService', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ RouterTestingModule, HttpModule ], providers: [ BaseRequestOptions, MockBackend, CageService, { provide: 'appHttpService', useClass: AppHttpService }, { provide: 'appHttpHelperService', useClass: AppHttpHelperService }, { provide:

How to spy on anonymous function using Jasmine

一笑奈何 提交于 2019-12-04 13:14:22
问题 I'm using Jasmine to test my angular application and want to spy on an anonymous function. Using angular-notify service https://github.com/cgross/angular-notify, I want to know whether notify function have been called or not. Here is my controller: angular.module('module').controller('MyCtrl', function($scope, MyService, notify) { $scope.isValid = function(obj) { if (!MyService.isNameValid(obj.name)) { notify({ message:'Name not valid', classes: ['alert'] }); return false; } } }); And here is

ReferenceError: module is not defined - Karma/Jasmine configuration with Angular/Laravel app

心不动则不痛 提交于 2019-12-04 08:47:53
问题 I have an existing Angular/Laravel app in which Laravel acts as an API to the angular frontend serving only JSON data. The page that loads the angular app, index.php , is currently served by Laravel. From there, Angular takes over. I'm have a very difficult time trying to get started with Karma/Jasmine. When running my tests using karma start or karma start karma.conf.js from the root directory of my project, I get the following error: ReferenceError: module is not defined Full output: INFO

Debugging karma-jasmine tests with node-inspector

帅比萌擦擦* 提交于 2019-12-04 08:42:07
Almost the same question as Debugging jasmine-node tests with node-inspector BUT does anyone know how to use node-inspector with karma? Install the node-inspector globally from NPM: npm install -g node-inspector Then start the node-inspector and background the process (use fg to bring it back to the foreground and kill %1 to stop it): node-inspector & And then start your test runner like in debug mode this node --inspect ./node_modules/karma/bin/karma start Then connect to the inspector from your local loopback. To start debugging, open the following URL in Chrome: chrome-devtools://devtools

Expected Response with status: null null for URL: null to equal 'Project11'

浪尽此生 提交于 2019-12-04 06:54:24
问题 I am using angular7 and doing unit testing in jasmine and karma. And I am facing error - Error: Expected Response with status: null null for URL: null to equal 'Project11'. My packages versions are - "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/jquery": "^3.3.22", "@types/node": "~8.9.4", "codelyzer": "~4.2.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~1.4.2",

AngularJS Unit Testing - Various patterns for injecting dependencies

北城余情 提交于 2019-12-04 06:52:11
I'm new to unit testing and am mainly learning from examples that I find. The problem is that I've seen so many different patterns that it's hard to understand what the differences are between them. And how to combine those patterns for various use cases. Below is one such pattern: var $rootScope, $window, $location; beforeEach(angular.mock.module('security.service', 'security/loginModal.tpl.html')); beforeEach(inject(function(_$rootScope_, _$location_) { $rootScope = _$rootScope_; $location = _$location_; })); var service, queue; beforeEach(inject(function($injector) { service = $injector.get

How to serve JSON files in karma

≡放荡痞女 提交于 2019-12-04 05:11:33
I am having great trouble to get Karma to serve json files that are needed in my application. I don't want to mock the json, I just need it to be served on the karma server. When I check in the Karma browser, I can load the HTML files in the template folder just fine. But the JSON files in the data folder are not found. But I have configured both folders in the exact same way! I tried to add the fixture plugin, but it has no effect on JSON files being served. My Karma configuration: module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg.

Karma error - Chrome have not captured in 60000 ms, killing

放肆的年华 提交于 2019-12-04 04:08:56
DEBUG LOG: E:\Projects\abb\Projects\WebApp\abb.web>karma start DEBUG [plugin]: Loading karma-* from E:\Projects\abb\Projects\WebApp\abb .web\node_modules DEBUG [plugin]: Loading plugin E:\Projects\abb\Projects\WebApp\abb.web\n ode_modules/karma-chrome-launcher. DEBUG [plugin]: Loading plugin E:\Projects\abb\Projects\WebApp\abb.web\n ode_modules/karma-jasmine. INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/ INFO [launcher]: Starting browser Chrome DEBUG [temp-dir]: Creating temp dir at C:\Users\Kunal\AppData\Local\Temp\karma-8 6563066 DEBUG [launcher]: C:\Program Files

Test an Angular2 Pipe that has a constructor method in Jasmine

China☆狼群 提交于 2019-12-04 03:39:46
问题 I am falling at the first hurdle testing an Angular Pipe that has a constructor. My Pipe is as follows: reverse.pipe.ts import { IterableDiffer, IterableDiffers, Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'reverse', pure: false }) export class ReversePipe implements PipeTransform { private cached: Array<any>; private differ: IterableDiffer<Array<any>>; constructor(private differs: IterableDiffers) { this.differ = this.differs.find([]).create(null); } transform(array: Array<any>