jasmine

Not able to spyOn the interleaved success callback of an ajax in Jasmine unit testing

∥☆過路亽.° 提交于 2019-12-24 00:35:14
问题 In source code I have one getJSON call with two success callback in the following structure. Source code to test: jsonMakeLineOrderData = $.getJSON(url, jsonData, function (data) { console.log("Inside 1st callback"); //… some other statement }).success(function (data) { // line# 1 console.log("Inside 2nd callback"); //… some other statement }); I am using Jasmine testing framework to test the success blocks of this call. To fake/mock the ajax call I have used spyOn utility. My Jasmine test

Jasmine: Testing whether a method is called by another method from another class

夙愿已清 提交于 2019-12-24 00:24:40
问题 I have 2 classes as below class B { public b() { return 1 } } class A { b: B = new B() public run() { return this.b.b() } } I tried to use the following test to test did method b() from class B, but the test is not working describe('A spy', () => { let a: A let b: B beforeEach(() => { a = new A() b = new B() spyOn(b, 'b') a.run() }) it('tracks that the spy was called', () => { expect(b.b).toHaveBeenCalled() }) }) Did i misunderstood jasmine's testing concept? i also tried `jasmine.createSpy',

Setup Jasmine Test Framework on MVC 5

故事扮演 提交于 2019-12-23 23:34:43
问题 I am having problems setting up the Jasmine Test Framework from nuget in my MVC 5 project in VS2013. I always get an error message when I run the SpecRunner.cshtml file. It keeps saying that the resource cannot be found but it doesn't specify which one. Anyone know how to properly setup a standalone SpecRunner.cshtml (without needing to go through the index page)? Here is what I currently have in my SpecRunner.cshtml @{ Layout = null; } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01

Angular unit test if component method is called according to a data from a service

南笙酒味 提交于 2019-12-23 22:36:37
问题 I can't figure out how to test if a component method is fired or not on service data condition... service looks like: @Injectable() export class SomeService { someData() { return true; } } comp: export class SomeComponent { constructor(private someService: SomeService) { if (this.someService.someData()) { this.someMethod(); } else { console.log('keep kalm!'); } } someMethod() { console.log('some method is fired!') } } test: describe('SomeComponent', () => { let component: SomeComponent; let

Promise resolved too late in angularjs jasmine test

雨燕双飞 提交于 2019-12-23 19:13:52
问题 I have the following jasmine test written with ng-describe , run with karma . (I am using es6-promise polyfill for PhantomJS) var myModule = angular.module('MyModule', []); myModule.service('MyService', [function() { return { getItems: function() { // this will be spied and mocked } }; }]); myModule.controller('MyController', ['$scope', 'MyService', function($scope, MyService) { $scope.items = []; $scope.refreshItems = function() { MyService.getItems().then( function ok(items) { $scope.items

AngularJS testing with Jasmine unable to call “angular.mock.module” while using angular-mocks.js

北慕城南 提交于 2019-12-23 18:35:29
问题 I'm trying to get a basic unit test working and am running into an issue using angular-mocks.js. Hopefully this code will explain my situation. describe("peconfigApp", function () { beforeEach(function() { angular.mock.module('peconfigApp'); }); describe("Binaries Controller", function () { it("should work", function () { expect(true).toBe(true); }); }); }); Jasmine result error: TypeError: Object #<Object> has no method 'module' at null.<anonymous> (http://localhost:58141/Tests/js/controller

Jasmine-jQuery loadFixtures is not defined

旧城冷巷雨未停 提交于 2019-12-23 17:47:15
问题 I'm still new to the whole jasmine things and in past few hours I stuck in this problem. I tried to load an external fixture file using loadFixture(). I use Jasmine 2.0.0 and Jasmine-jQuery 2.0.5. ReferenceError: loadFixtures is not defined at Suite.<anonymous> (--appname--/app/assets/Tester/spec/ChannelSpec.js:5:6) at Env.describe (--appname--/app/assets/Tester/lib/jasmine-2.0.0/jasmine.js:613:25) at jasmineInterface.describe (--appname--/app/assets/Tester/lib/jasmine-2.0.0/boot.js:37:18) at

How to change $httpBackend when[method] statements between requests in unit testing?

点点圈 提交于 2019-12-23 16:34:25
问题 In my testing i initiate some model data and mock the response: beforeEach(function(){ var re = new RegExp(/^http\:\/\/.+?\/users-online\/(.+)$/); $httpBackend.whenGET(re).respond({id:12345, usersOnline:5000}); }); it('should find 5000 users in channel 12345', function(){ expect( UsersOnlineService.data.usersOnline).toEqual( 50000); }); then say in the next test statement i want the updated value for the channel. Everyone has left, and hypothetically this would trigger other behavior, so i

Unable to generate Report when using jasmine-reporters in protractor

穿精又带淫゛_ 提交于 2019-12-23 15:52:13
问题 i Used the following code in config var jasmineReporters = require('jasmine-reporters'); onPrepare: function() { browser.driver.manage().window().maximize(); browser.params.envi='DEVINT'; //For output reports jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter('./test', true, true)); }, When i ran the tests it ran successfully, but im not seeing any reports generated. Any Suggestions? 回答1: Not sure it would help but here is what is working for me: onPrepare: function () {

Angular jasmine test not able to trigger Observable created with fromEvent rxjs operator

浪子不回头ぞ 提交于 2019-12-23 12:44:25
问题 I have a simple case. The standard AppComponent of an Angular app contains a ChildComponent which is defined in its own module ChildModule . The template of ChildComponent is very simple <div class="child" (click)="testClick($event)"></div> ChildComponent has an even simpler testClick(event) method that just logs a message on the console. testClick(event) { console.log(event); } Now I want to build a test on AppComponent simulating a click on ChildComponent . This is the code of the test