karma-jasmine

Angular-cli and Karma with jQuery

孤人 提交于 2019-12-10 23:12:24
问题 I have searched the web and could not find a solution for my current problem, even though seems to be a very common issue ... When running ng test I find that the Karma browser opens and shows nothing: Also, this is my console: In order to use jQuery, I have done the things explained here. This is my lib.ts (basically the same as vendor.ts ) : // jQuery declare let jQuery: any; // RxJS import 'rxjs/add/operator/map'; import 'rxjs/add/operator/mergeMap'; // Dependencies window['jQuery'] =

error TS1127: Invalid character when running Karma tests in Angular 7

隐身守侯 提交于 2019-12-10 21:25:45
问题 I'm getting errors error TS1127: Invalid character in the Visual Studio Code terminal, when running a Karma test for an Angular 7 app CLI version - 7.3.9 I have one single Karma test specification in the app (I removed all of the spec files that the Angular CLI generates, but left the existing Jasmine and Karma npm packages in place) Jasmine is the test runner This doesn't seem to be an invalid character or whitespace issue - this didn't work - Angular compile error: src/app/login/login

How do I test the HTML pointed to by the templateUrl of an angular directive?

99封情书 提交于 2019-12-10 21:22:28
问题 I have a directive: app/controllers/battle.js angular.module('myModule') .controller('myController', ['$scope', function($scope){ $scope.sayHello = function(){console.log('hello');}; }]) .directive('myDirective', function(){ return { templateUrl: '../views/testView.html' } }); That directive is called as follows: app/views/routeOne.html <my-directive ng-controller='myController'></my-directive> The directive templateUrl points to a file that looks like: app/views/testView.html <div id=

'TypeError: undefined is not a function' using Protractor

给你一囗甜甜゛ 提交于 2019-12-10 19:42:59
问题 I am aware there are many topics on this error code however I am struggling to find any solutions that help (or maybe I'm just stupid). I am building a Protractor test for a web page, and my original javascript worked perfectly. But I wanted to convert it all into using page objects, to make it easier to edit and understand as well as avoid code repetition. The first page object I use for logging in works perfectly fine, however my second page object for adding new users does not. The main

Unit Test Karma Jasmine SyntaxError: Parse error on “&” Angular Directive binding

≯℡__Kan透↙ 提交于 2019-12-10 19:25:00
问题 I get SyntaxError: Parse error at my directive line where I want to use a "&" one-way binding from a parent directive's method myApp.directive('datasourceDeleteBtn', [function() { return { restrict: 'E', replace: true, template: '<a href="#">&#x2715</a>', scope: { datasourceIndex: '@', removeParentDiv: '&' }, link: link }; function link(scope, element, attr) { element.bind('click', function(event) { event.preventDefault(); scope.deleteDatasource(scope.datasourceIndex); }); // Notify parent

Mocking Angular Material Dialog afterClosed() for unit test

喜你入骨 提交于 2019-12-10 19:09:27
问题 I am opening my mat-dialog with the following function: accept() { let dialogRef = this.dialog.open(AcceptDialogComponent, { data: { hasAccepted: false } }) dialogRef.afterClosed().subscribe(result => { console.log(result); if (result.hasAccepted === true) { this.leadService.acceptLead(this.holdingAccountId, this.lead.id) .pipe( takeUntil(this.onDestroy$) ) .subscribe (acceptLeadRes => { console.log(acceptLeadRes); this.leadService.updateLeadAction('accept'); }, (err: HttpErrorResponse) => {

How to unit test an Angular 1.5 Component template?

隐身守侯 提交于 2019-12-10 18:05:42
问题 So, here's my test: describe('My Test', function(){ var $componentController, $compile, controller, scope; beforeEach(inject(function($injector, $rootScope, $templateCache){ $templateCache.put('my-component.html', '<h1>{{ $ctrl.foo }}</h1>'); $componentController = $injector.get('$componentController'); var bindings = { foo: 'A Foo' }; scope = $rootScope.$new(); controller = $componentController('myComponent', { $scope: {} }, bindings); })); it('should render the correct html', function(){

Error: No provider for Compiler! DI Exception Angular 2 Testing

倾然丶 夕夏残阳落幕 提交于 2019-12-10 17:55:36
问题 The given unit test throws error when executed using npm test command. It says there was a DI Exception with error message "Error: No provider for compiler!" import {TestComponentBuilder} from "@angular/compiler/testing"; import { expect, it, describe, async, inject, beforeEach, beforeEachProviders } from "@angular/core/testing"; import {provide} from '@angular/core'; import {TestService} from "../services/Test.service"; import {TestComponent} from "./Test.component"; describe('Component:

Angular Testing Error: Can't resolve all parameters for Service:

大城市里の小女人 提交于 2019-12-10 17:48:01
问题 I'm new to testing. I have a service and a spec file that when run I get the following error: Error: Can't resolve all parameters for DashboardService: (?). error properties: Object({ ngSyntaxError: true }) The spec file looks like this: import { TestBed } from '@angular/core/testing'; import { DashboardService } from './dashboard.service'; import { ApiService } from './../api.service'; describe('The Dashboard Service', () => { beforeEach(() => { TestBed.configureTestingModule({ providers:

AngularJS & Jasmine/Karma - Uncaught ReferenceError: require is not defined

那年仲夏 提交于 2019-12-10 17:18:17
问题 I'm trying to test a angular app using Jasmine-Karma. I'm total newbie in the "testing/console/npm" field, so I'd like to ask you for an easy explanation (and some fix as well) what is causing the error Uncaught ReferenceError: require is not defined at /Applications/MAMP/htdocs/..../node_modules/angular-mocks/ngAnimateMock.js:1 I also found out that there is no ngAnimateMock.js inside angular-mocks folder. Here is my karma.conf.js file module.exports = function(config) { config.set({