jasmine

Trying to understand Jasmine's toHaveBeenCalled() matcher

自闭症网瘾萝莉.ら 提交于 2019-12-04 23:55:58
I am new to jasmine here is my src file in which i create Auth class function Auth() { } Auth.prototype.isEmpty = function(str) { return (!str || 0 === str.length); } Auth.prototype.Login = function (username , password) { if (this.isEmpty(username) || this.isEmpty(password)) { return "Username or Password cann't be blank "; } else { return "Logged In !"; } } now i want to test jasmine's toHaveBeenCalled() matcher . Here is what i write it("should be able to Login", function () { spyOn(authobj); expect(authobj.Login('abc', 'abc')).toHaveBeenCalled(); }); but it says that undefined() method

How to unit test Angular controller with $scope.$on?

本小妞迷上赌 提交于 2019-12-04 23:50:06
I have a controller with an event listener in my Angular app, defined as follows. angular.module('test').controller('TestCtrl', function($rootScope, $scope, testService) { [...] $scope.$on("myEvent", function(args, value) { testService.doStuff(value); }); }); This works perfectly in the app itself. However, when I try to unit test the functionality of the controller (using Jasmine and Karma ), each test method throws the following error: TypeError: $scope.$on is not a function in [...]/testController.js I create the controller in my test methods as follows. it('does stuff', inject(function(

Jasmine spies callThrough and callFake

懵懂的女人 提交于 2019-12-04 23:32:06
I have a scenario whereby I want to call done() on a beforeEach after a callback has been invoked. I tried to do this as follows : spyOn(scope, 'onAdmin').and.callThrough().and.callFake(function(){done()}) But I'm not sure I get the right behaviour. Essentially what I want to achieve is to be able to call done() after each callback is done doing what it does. UPDATE: workaround solution scope.onAdminBackup = scope.onAdmin; spyOn(scope, 'onAdmin').and.callFake(function(admin) { scope.onAdminBackup(); done() ; }) I have never chained these kinds of functions together cuz in my mind they seem to

Unit Testing socket.io in Angular

只愿长相守 提交于 2019-12-04 23:06:04
I am trying to unit test an angular service in my application, which creates socket.io client. My service looks something like this: export class SocketService { private name: string; private host: string = window.location.protocol + "//" + window.location.hostname + ":3000"; socket: io.Socket; constructor() { } subscribeEvent(name: string): Observable<IJobResp> { this.setup(name); return new Observable(observer => { this.socket.on('job', val => observer.next(val)) }) } private setup(name: string) { this.name = name; let socketUrl = this.host + "/" + this.name; this.socket = io.connect

Template parse error in Jasmine test but not actual app

折月煮酒 提交于 2019-12-04 22:49:47
I've developed a Jasmine spec to test an angular 2 component MiddleRowComponent . When I run the jasmine test, it gives this error: zone.js:388 Unhandled Promise rejection: Template parse errors: 'circles' is not a known element: 1. If 'circles' is an Angular component, then verify that it is part of this module. 2. If 'circles' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("</div> <div class="col-md-10 col-sm-12 offset-md-1 flex-xs-middle" id="circles-div"> [ERROR ->]<circles (onWordChanged)="onWordChanged($event)"

Testing javascript inside IIFE

删除回忆录丶 提交于 2019-12-04 22:25:50
My team leader wants me to wrap my js code inside an IIFE immediatly-invoked function expression. I can't figure out how to spyOn in my jasmine spec file. How would I spyOn the follow: (function(){ function_1(){...} function_2(){...} }); spyOn(window,'function_1') doesn't work. Passing window into the IIFE doesn't work. Trying both (x=function()... and (function x() ... then spyOn(x,'function_1') doesn't work either. I couldn't find anything on-line about this. @user29998, if you can expose those functions to test via a return block, you can do something as found on this jsbin link: http:/

.detectChanges() not working within Angular test

删除回忆录丶 提交于 2019-12-04 21:45:37
问题 I've been tasked with writing tests for a chat app developed with Angular. Below is the snippet of Angular template code I'm currently writing tests for: <div class="title-menu-container" fxLayoutAlign="center center"> <button id="save-title-button" mat-icon-button *ngIf="titleInputEdit; else settings"> <mat-icon class="secondary-text" (click)="saveTitle(titleInput.value)">check</mat-icon> </button> <ng-template #settings> <button mat-icon-button [matMenuTriggerFor]="menu" [disabled]="!

Generate simple html based on jasmine-allure-reporter

余生颓废 提交于 2019-12-04 21:37:19
I'm using jasmine-allure-reporter and the report is simply awesome. Only complaint over the reporter is that I miss option to enable only failed screenshots to be saved and possibility to send it via e-mail. I know that is not possible: How to send an email of allure report? My question is whether I can somehow generate a simple html file with few data based on the allure reports, so that I'll be able to send it via e-mail to relevant people. Hope you have added this in your conf file: onPrepare: function () { browser.manage().timeouts().implicitlyWait(15000); var AllureReporter = require(

Error while integrating html with testacularjs

我的未来我决定 提交于 2019-12-04 21:25:10
问题 How do I integrate (html) fixtures with testacular? Is there any recommendation for performing DOM based tests or is it an anti-pattern? Objective : I am trying to test a custom module which parses the DOM tree and creates a new data structure. The DOM tree can be dynamic (like contents of a html/markdown editor) and hence is not a good candidate for end to end testing Problem : I am trying to use jasmine-jquery for this DOM testing and in my testacular.conf.js, I have the section to allow

Can Blanket.js work with Jasmine tests if the tests themselves are loaded with RequireJS?

旧城冷巷雨未停 提交于 2019-12-04 20:30:24
We've been using Jasmine and RequireJS successfully together for unit testing, and are now looking to add code coverage, and I've been investigating Blanket.js for that purpose. I know that it nominally supports Jasmine and RequireJS, and I'm able to successfully use the "jasmine-requirejs" runner on GitHub, but this runner is using a slightly different approach than our model -- namely, it loads the test specs using a script tag in runner.html, whereas our approach has been to load the specs through RequireJS, like the following (which is the callback for a requirejs call in our runner): var