jasmine

$scope.$on not working in Jasmine SpecRunner

核能气质少年 提交于 2019-12-12 05:27:12
问题 I've just started using Jasmine for testing an AngularJS app. I believe I'm doing all the imports on the SpecRunner but I get the error: TypeError: $scope.$on is not a function I'm using this in my controller as follows: app.controller('asstCtrl', function($scope, $uibModal, $interval, $document) { $scope.$on('$includeContentLoaded', function() { $scope.doStuff(); }); }); ... My SpecRunner test is looking like this: describe('calculator', function(){ beforeEach(module('asst')); it('basic',

Testing directive in Angular 2 + Jasmine I am getting an error

梦想的初衷 提交于 2019-12-12 05:19:11
问题 I am getting the error below when I run the test using Angular 2 + Jasmine. Does anyone know how can I solve this problem? I already have imported the directive in app.module.ts. Can't bind to 'highlightData' since it isn't a known property of 'li'. ("[ERROR ->][highlightData]="item.name"> list.component.ts <ul> <li *ngFor="let item of list" [highlightData]="item.name">{{item.name}}</li> </ul> highlight-data.directive.ts import { Directive, SimpleChanges, Input, OnChanges, ElementRef,

Unit Test AngularJs Jasmine error: Expected spy login to have been called

随声附和 提交于 2019-12-12 05:09:37
问题 I'm new testing with AngularJs and Jasmine. I'm trying to test a login POST $http service. I'm not pretty sure how to do it, but what I have I'm getting an error and I dont know why. This is my login.service.js: (function () { 'use strict'; angular .module('app') .service('loginService', loginService); /** @ngInject */ function loginService($http) { var url = 'http://localhost:8080/login'; var service = { login: login }; return service; // ////////// // function login(user) { return $http

An Angular2 app with karma & jasmine throws errors with multi-level directory structure

旧城冷巷雨未停 提交于 2019-12-12 04:36:29
问题 I am building an Angular 2 app with the current 4.0.0-beta.1 release. After many hours of struggle, I got karma running. I'm now trying to get a jasmine tautology test (true=true) to run, but karma reports: "Uncaught ReferenceError: describe is not defined" Here are the relevant code sections: karma.conf.js module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine'], // these plugins seem to be necessary. Without them, an error about a missing require in app

Globally injecting am AngularJS factory mockup when testing with Jasmine

点点圈 提交于 2019-12-12 04:34:33
问题 I'm creating unit tests for my AngularJS application's controllers. In myapp.run I'm injecting and using a factory, called UsersFactory, somehow like this: myApp.run(['$rootScope','UsersFactory', function ($rootScope,UsersFactory) { UsersFactory.getMe().then(function(data) { //.. }); }]); I created a Mock for UsersFactory called UsersFactoryMock. It has the same methods as UsersFactory, but the implementation is different (fake) of course. I would like to inject UsersFactoryMock, in order to

Test a function passed as argument to another function in Jasmine

佐手、 提交于 2019-12-12 04:33:02
问题 I am getting below error(which is OK!) when called tohaveBeenCalledWith : spy showError to have been called with [ '33' ] but actual calls were [ Function, 403 ] Is there any way I can test Function that the function called with? Assuming that the argument Function is testFun , How can I test if $window.location.href hascorrect value applied function testFun(errorStatus) { switch (errorStatus) { case 401: $window.location.href = url1; break; case 403: $window.location.href = url2; break;

Expect text to be absent in pagesource-Protractor

被刻印的时光 ゝ 提交于 2019-12-12 04:26:27
问题 I need to get the pagesource & then check whether the text "hello world" is absent in the pagesource. I am trying the below method which is failing. var page_source=browser.getPageSource().then(function (text){ expect(text).not.toContain("hello world"); }); Any suggestions ?? Error trace: Stack: Error: Failed expectation at Object.<anonymous> (C:\Protractor\Testcases\test.js:56:38) at C:\Protractor\node_modules\jasminewd2\index.js:110:25 at new ManagedPromise (C:\Protractor\node_modules

Ajax test code throwing error

倾然丶 夕夏残阳落幕 提交于 2019-12-12 04:23:38
问题 I am testing a code using jasmine and creating a mock object for ajax method spyOn($,'ajax').and.callFake(function(e){ console.log("is hitting"); }) to test the following piece of code $.ajax({ url: AppManager.defaults.contextPath + "/solutions/mcn/mcn-lookup-list", data: { mcnNumber : mcnNumberData, mcnCustomerName : mcnCustomerNameData }, dataType: "json", type: "GET", global: false }) .done(function(data) { solution.CommonObjects.theSolution.orderHandoff.mcnSearchData = self

AngularJs Jasmine Unit test fails with Unexpected Request

假如想象 提交于 2019-12-12 04:16:46
问题 Following is my myService.spec.js : 'use strict'; describe('myService', function () { var dependentService,dependentService1,rootScope,$q; beforeEach(module('myModule.myConfig')); beforeEach(module('myModule')); beforeEach(inject(function (_myService_, _$rootScope_, _$q_,_dependentService1_,_dependentService_) { myService= _myService_; rootScope = _$rootScope_.$new(); $q = _$q_; dependentService1= _dependentService1_; dependentService= _dependentService_; spyOn(dependentService1,'setPath');

How to test an asynchronous function using karma/Jasmine in ionic2?

*爱你&永不变心* 提交于 2019-12-12 04:03:21
问题 Below I have written down the code in which there is an asynchronous function, that uses setTimeout() internally and prints message after 3seconds. I have to write the spec using Jasmine. I have followed the docs but I didn't get how to apply this in the code. home.ts //implementing only function written in a class.All imports are done properly. click(){ function delayedAlert(message: string, time: number, cb) { return setTimeout(() => cb(message), time); } delayedAlert('Aditya3', 3000,