jasmine

Jasmine 2.0: refactoring out 1.3's runs() and waitsFor()

∥☆過路亽.° 提交于 2019-12-03 06:53:27
问题 The recently released Jasmine 2.0 removes the waits functions and the runs() from the Async Jasmine 1.3. I have old 1.3 tests I'd like to transition to the new style. For the waits, in most cases it seems like you can write beforeEach() and afterEach() carefully for the same effect. What is the best way to reproduce the runs() which simply executes the contained functions sequentially? My first try: runs(function() { expect(true).toBe(true); } becomes (function() { expect(true).toBe(true); })

Angular 2: How to mock ChangeDetectorRef while unit testing

冷暖自知 提交于 2019-12-03 06:47:54
I have just started with Unit-Testing, and I have been able to mock my own services and some of Angular and Ionic as well, but no matter what I do ChangeDetectorRef stays the same. I mean which kind of sorcery is this? beforeEach(async(() => TestBed.configureTestingModule({ declarations: [MyComponent], providers: [ Form, DomController, ToastController, AlertController, PopoverController, {provide: Platform, useClass: PlatformMock}, { provide: NavParams, useValue: new NavParams({data: new PageData().Data}) }, {provide: ChangeDetectorRef, useClass: ChangeDetectorRefMock} ], imports: [

How do I test angularjs directive to spy on the function call?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:04:11
Code below executes but complains about element.popover not being invoked. I can't seem to figure out what the issue is. Thanks for help in advance. directive: angular.module('directives', []). directive('popOver', function ($http) { return { restrict:'C', link: function (scope, element, attr) { element.bind('mouseover', function (e) { $http.get("someurl" + attr.chatid + ".json").success(function (data) { element.popover({content: data.firstName + " " + data.lastName }); }); }); } } }) Jasmine test: 'user strict' describe('directives', function() { beforeEach(module('directives')); describe(

Error: Timeout - Async callback was not invoked within timeout specified… .DEFAULT_TIMEOUT_INTERVAL

自古美人都是妖i 提交于 2019-12-03 06:03:58
I have an angular service class : - angular.module('triggerTips') .service('userData', function ($rootScope, $http, $log, $firebase) { this._log = { service : 'userData' }; // Synchronized objects storing the user data var config; var userState; // Loads the user data from firebase this.init = function(readyCallback) { var log = angular.extend({}, this._log); log.funct = 'init'; var fireRef = new Firebase('https://XYZfirebaseio.com/' + $rootScope.clientName); config = $firebase(fireRef.child('config')).$asObject(); userState = $firebase(fireRef.child('userState').child($rootScope.userName)).

Protractor flakiness

巧了我就是萌 提交于 2019-12-03 06:02:51
问题 I maintain a complex Angular (1.5.x) application that is being E2E tested using Protractor (2.5.x). I am experiencing a problem with this approach, which presents primarily in the way the tests seem flaky. Tests that worked perfectly well in one pull request fail in another. This concerns simple locators, such as by.linkTest(...). I debugged the failing tests and the app is on the correct page, the links are present and accessible. Has anyone else experienced these consistency problems? Knows

How to unit test an angularjs promise chain using $httpBackend

邮差的信 提交于 2019-12-03 05:59:16
Using AngularJS, I am trying to unit test a function that makes multiple calls to $http. My test looks something like this: it('traverses over a hierarchical structure over multiple chained calls', function() { myService.traverseTheStuff() .then(function(theAggregateResult) { // ...is never fulfilled }); $httpBackend.flush(); }); Other single-call tests will register the callback passed to .then() and execute it as soon as I call .flush(). The code under test looks something like this. function traverseTheStuff(){ // This will make a call to $http to fetch some data return getRootData() // It

How to use Jasmine spies on an object created inside another method?

旧巷老猫 提交于 2019-12-03 05:51:39
问题 Given the following code snippet, how would you create a Jasmine spyOn test to confirm that doSomething gets called when you run MyFunction ? function MyFunction() { var foo = new MyCoolObject(); foo.doSomething(); }; Here's what my test looks like. Unfortunately, I get an error when the spyOn call is evaluated: describe("MyFunction", function () { it("calls doSomething", function () { spyOn(MyCoolObject, "doSomething"); MyFunction(); expect(MyCoolObject.doSomething).toHaveBeenCalled(); }); }

How can I test a controller with resolve properties in AngularJS?

爷,独闯天下 提交于 2019-12-03 05:49:17
问题 How can one test a controller with resolve properties? It throws an error: Unknown provider: InitProvider, during testing, understandably. How can I test it? I use the init property in the route config to load data and pass it along to the controller at controller instantiation so the route doesn't change before data is loaded. $routeProvider .when('/topic/:topic_id/content/:content_id', { templateUrl: 'views/content.html', controller: 'ContentCtrl', resolve: { init: ContentCtrl.init } }); Is

Using importsScripts within Blob in a karma environment

馋奶兔 提交于 2019-12-03 05:44:11
I am working on a small project of mine using karma, and jasmine. My targeted browser is chrome 32. I am trying to import scripts within a web worker whom I have instanciated through a blob as follows : describeAsyncAppliPersephone("When the application project to DOM", function() { it("it should call the function of DomProjection in the project associated with its event", function() { var eventSentBack = { eventType: 'testReceived', headers: { id: 14, version: 4 }, payLoad: { textChanged: 'newText' } }; var isRendered = false; var fnProjection = function(event, payload) { isRendered = true; }

Unit testing using Jasmine and TypeScript

空扰寡人 提交于 2019-12-03 05:30:39
问题 I am trying to get a unit test written in Typescript using Jasmine to compile. With the following in my unit-test file, Resharper prompts me with a link to import types from jasmine.d.ts. /// <reference path="sut.ts" /> /// <reference path="../../../scripts/typings/jasmine/jasmine.d.ts" /> describe("Person FullName", function () { var person; BeforeEach(function () { person = new Person(); person.setFirstName("Joe"); person.setLastName("Smith"); }); It("should concatenate first and last names