jasmine

Issue with jasmine expectations not being tested/evaluated because of simulated mock error

安稳与你 提交于 2019-12-12 03:56:48
问题 I am trying to unit test a angular 2 component and simulate an error (400/bad request) from the http backend. Here is my code: describe('Component: UserAccountActivationComponent', () => { let fixture: ComponentFixture<UserAccountActivationComponent>; let userAccountActivationComponent: UserAccountActivationComponent; const observableMock = Observable.of('Some Observable'); beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ MockBackend, BaseRequestOptions, { provide: Http,

typescript-collections jasmine visual studio 2015

我的梦境 提交于 2019-12-12 03:45:16
问题 I am currently in the process of learning how to test my typescript code using VS2015, with resharper, and Jasmine (v 2.4.1) and it is not going very smooth. I trying to use typescript-collections from https://github.com/basarat/typescript-collections. The following seems to work fine: describe("collection Tests", () => { it("collection should work", () => { expect("123").toBe("123"); }); }); When i execute the test from VS2015 (using resharper) then it starts my webbrowser and reports that

mocking xhr calls in Jasmine

我的未来我决定 提交于 2019-12-12 03:37:45
问题 I have a question regarding mocking xhr in Jasmine. I have the following Javascript situation: function Test1(){ // some code Test2({ readyState: 4, responseText: "", status: 200, statusText: "OK" }); } function Test2(xhr){ var token = xhr.getResponseHeader("csrftoken"); var csrfCtrl = $("#token"); if (token != null && csrfCtrl != null) { csrfCtrl.val(token); } } Now I want to spyOn the xhr.getResponseHeader() function but I can not find out how I could do that. I tried something like this:

ReferenceError: module is not defined in Jasmine Angular js

一个人想着一个人 提交于 2019-12-12 03:18:22
问题 I am begining with Angular and with unit testing, this is my first code, and it isn't working. I searched for a solution but I dont know what I am doing wrong. If anyone can explain to me what is the mistake, I would thank you. This is all my code. <!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-mocks.js"><

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

unit testing fading out directive - cannot see the right CSS class added -angular & jasmine

旧街凉风 提交于 2019-12-12 02:53:35
问题 i'm trying to test the very simple directive i have made. .directive('cssnotification', [ '$timeout', function($timeout) { return { restrict:'A', link:function(scope, element, attrs) { scope.$watch('success',function(newVal ,oldVal){ if(newVal){ $timeout(function(){ scope.success = false; },1000); } },true) } } }]) This directive makes some element to be visible for 1 second and after that - fades it out. (here is the fiddle that demonstrates the problem) I know that for perform the fadingOut

Jasmine junit testing of delegate callback of function args

雨燕双飞 提交于 2019-12-12 02:49:59
问题 I have recently started using jasmine to write junit testcase for one of our application. I am stuck at this point on how to call the callBack function of the spied function. setProfile :function(userProfile,callback){ var user; var subjectInfo; iService.searchForAccess(subjectInfo , queryCalback); function queryCalback(err, userProfile) { if(err){ callback(true,errorMessage) }else{ callback(false,null) } } } Now in my spec i want to mock the call to iService.searchForAccess real world

AngularJS - Controller not registered

蹲街弑〆低调 提交于 2019-12-12 02:33:50
问题 I am starting out on AngularJS Unit Testing and I am getting an error like Controller with name "SiteCtrl" is not registered. What I am doing wrong here? describe('#hasFormError', function () { var $rootScope,form, templateHtml, ctrl,$scope,scope; angular.module("TestApp"); beforeEach(function () { angular.module("TestApp"); }); beforeEach(inject(function ($rootScope, $controller, $compile, $templateCache) { $scope = $rootScope.$new(); ctrl = $controller; ctrl('SiteCtrl', { $scope: scope });

How do I test AngularJS controllers using RequireJS?

那年仲夏 提交于 2019-12-12 02:33:46
问题 Here's my Jasmine spec, define(['app', 'angular', 'angularResource', 'angularMocks'], function() { describe('App module tests', function(){ var module, $rootScope, scope, AppCtrl; beforeEach(function () { module = angular.module("MyApp"); inject(function($rootScope, $controller){ // The injector unwraps the underscores (_) from around the parameter names when matching scope = $rootScope.$new(); AppCtrl = $controller('AppCtrl', {$scope: scope}); }); }); }); }); In my app.js, I have.. var MyApp