karma-jasmine


Can't run Karma with Angular 1.4.9 with error angular.module(…).info is not a function

限于喜欢 提交于 2020-01-25 23:22:53
问题 When running karma start --single-run there is an error Chrome 62.0.3202 (Linux 0.0.0) ERROR Uncaught TypeError: angular.module(...).info is not a function at /home/ali/bedopedia/client/node_modules/angular-mocks/angular-mocks.js:80 When I opened anguler-mocks.js there is a function called info and it need angular 1.6 .info({ angularVersion: '1.6.6' }) here is package.json file "devDependencies": { "angular-mocks": "^1.6.0", "grunt": "^0.4.5", "grunt-jsmeter": "^0.3.1", "jasmine-core": "^2.5

Unit testing and mocking a service with DI

隐身守侯 提交于 2020-01-24 10:01:05
问题 I have been struggling with this for a while, and I'm hoping someone can help. I have a component that uses a service to get data. I am attempting to add unit tests to it. My problem is that the tests always fail with "Error: No provider for Http". Here is my code: Service: import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import 'rxjs/add/operator/map'; import { Contact } from './contact.model'; @Injectable() export class

Karma's base directory location

一个人想着一个人 提交于 2020-01-24 05:41:05
问题 Unable to load template fixtures for my tests while using karma. To simplify, Went to c:\ Created a 1.txt text file. Made a simple karma init file containing: basePath: '', Started karma using: C:\> karma start .\sample.conf.js Chrome opened up at: http://localhost:9876/?id=49209467 I then tried to navigate to: http://localhost:9876/base/1.txt but got a "NOT FOUND" error message in the browser, and a message from karma: WARN [web-server]: 404: /base/1.txt What am I missing here? 回答1: Found

Jasmine unit test for angular service In controller

£可爱£侵袭症+ 提交于 2020-01-23 13:17:09
问题 I'm new to jasmine framework. I've gone through some tutorials and learned and started writing unit tests. 'facing one issue here is the description. I have a controller where i can invoke a service call to get the data. See the code below. $scope.getEmpInfo = function() { EmpService.getInfo($scope.empid) .then(function(data) { $scope.empData = data; $scope.populateEmpData($scope.empData); }, function(reason) { //do nothing } } Now, i want to write a unit test for the above method. Im able to

Angular - Karma - ngrx - No provider for Store

半城伤御伤魂 提交于 2020-01-23 07:22:42
问题 In one of my unit tests, I'm trying to mock @ngrx/store. I've used the technique successfully in another spec file, but when trying to use it in this one, I'm getting an injection error saying No provider for Store! Below is the relevant code from the spec file: beforeEach(async(() => { const emptyState = { opportunities: { list: { items: [], page: 1, total: 0 } } }; const mockStore = new MockStore<MockAppState>(emptyState); TestBed.configureTestingModule({ declarations: [

Jasmine - How to test a stylesheet directive

岁酱吖の 提交于 2020-01-16 20:36:16
问题 I have written a directive that interrogates the current URL, and loads the corresponding freestyle. The problem i am facing is how can i test the link function: HTML: <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>CSS Test</title> <link get-style-directive /> </head> Directive: app.directive('getStyleDirective', ["$compile", "$location", function($compile, $location) { return { replace: true, scope: true, link: function(scope, element, attrs) { var urlValue = $location

How to test code inside $(window).on(“load”, function() {}); in Jasmine

余生颓废 提交于 2020-01-15 04:20:29
问题 I have a javascript below, which appends a DIV on page load and hides it after 3 sec. var testObj = { initialize: function() { var that = this; $(window).on("load", function() { (function ($) { //Append Div $('body').append("<div>TEST</div>"); })(jQuery); that.hideAppendedDiv(); }); }, hideAppendedDiv: function() { //Hide appended Div after 3s setTimeout(function(){ $("div").hide(); }, 3000); } }; //call Initialize method testObj.initialize(); How to write Jasmine test cases for the methods

How to mock window.screen.width in Angular Unit Test with Jasmine

血红的双手。 提交于 2020-01-14 13:51:09
问题 I have a BreakpointService, which tells me - depending on the screen width - in which SidebarMode (closed - minified - open) I should display my Sidebar. This is the main part of the service: constructor(private breakpointObserver: BreakpointObserver) { this.closed$ = this.breakpointObserver.observe(['(min-width: 1024px)']).pipe( filter((state: BreakpointState) => !state.matches), mapTo(SidebarMode.Closed) ); this.opened$ = this.breakpointObserver.observe(['(min-width: 1366px)']).pipe( filter

karma-typescript: import JS file with Async keyword

不羁岁月 提交于 2020-01-14 07:48:11
问题 I'm using karma-typescript, with this karma config file : karmaTypescriptConfig: { compilerOptions: { target: "es5", lib: ["dom", "es2015", "es2017"] }, bundlerOptions: { transforms: [require("karma-typescript-es6-transform")()] } }, In my spec files, I have this code : import {} from './local/lib.js' In my lib.js, I have this code : async function() {} When executing my tests with npm test , I have this error : ERROR [source-reader.karma-typescript] Error parsing code: Unexpected token (X:Y)

AngularJS: how to test directive which gives focus to element?

半世苍凉 提交于 2020-01-13 13:52:12
问题 Note: the suggested link is an answer to a question about a service, and doesn't give a clear explanation on how to solve this issue I'm trying to setup a karma test for my simple (and working) AngularJS autofocus directive: app.directive('autofocus', function ($timeout) { return { replace: false, link: function (scope, element, attr) { scope.$watch(attr.autofocus, function (value) { if (value) { $timeout(function () { element[0].focus(); console.log('focus called'); }); } } ); } }; }); This

工具导航Map