jasmine

Unit test Angular 2 service subject

房东的猫 提交于 2019-12-05 07:35:13
I'm trying to write a test for an angular service which has a Subject property and a method to call .next() on that subject. The service is the following: @Injectable() export class SubjectService { serviceSubjectProperty$: Subject<any> = new Subject(); callNextOnSubject(data: any) { this.serviceSubjectProperty$.next(data); } } And the test file for that service: import { TestBed, inject } from '@angular/core/testing'; import { SubjectService } from './subject.service'; describe('SubjectService', () => { beforeEach(() => { TestBed.configureTestingModule({ providers: [ SubjectService ] }); });

Cannot read property 'injector' of null jasmine angular 2

元气小坏坏 提交于 2019-12-05 06:41:18
I'm getting this error when running a jasmine spec in angular 2: Cannot read property 'injector' of null jasmine angular 2 stack trace: TypeError: Cannot read property 'injector' of null at TestBed._createCompilerAndModule (http://localhost:3002/node_modules/@angular/core/bundles/core-testing.umd.js:834:48) at TestBed._initIfNeeded (http://localhost:3002/node_modules/@angular/core/bundles/core-testing.umd.js:800:43) at TestBed.createComponent (http://localhost:3002/node_modules/@angular/core/bundles/core-testing.umd.js:884:18) at Function.TestBed.createComponent (http://localhost:3002/node

Is 'repeater' in this angular tutorial a jasmine concept?

时间秒杀一切 提交于 2019-12-05 05:49:04
Looking through angular js tutorial , I do not understand where the repeater (function?) comes from in a jasmine test. Is this a jasmine or an angular construct? The page does have an ng-repeat attribute in a <li> element - but I dont see how that translates to the reference to 'repeater' in the test it('should be possible to control phone order via the drop down select box', function() { //let's narrow the dataset to make the test assertions shorter input('query').enter('tablet'); //where does 'repeater' below come from? expect(repeater('.phones li', 'Phone List').column('phone.name')).

AngularJS inject service mock inside service tests

与世无争的帅哥 提交于 2019-12-05 05:33:34
I have been trying to test a service to no avail for some time now and was hoping for some help. Here is my situation: I have a service looking a little like this myModule.factory('myService', ['$rootScope', '$routeParams', '$location', function($rootScope, $routeParams, $location) { var mySvc = { params: {} } // Listen to route changes. $rootScope.$on('$routeUpdate', mySvc.updateHandler); // Update @params when route changes mySvc.updateHandler = function(){ ... }; ... ... return mySvc; }]); And I want to mock the services injected into 'myService' before the service gets injected into my

AngularJS + Protractor sum all row values in repeater

試著忘記壹切 提交于 2019-12-05 05:00:02
问题 I'm testing AngularJS with Protractor, I have a repeater and I'm trying to sum all values in the rows, and compare it to the summary line value. Here's my HTML: <table> <th> <td>100</td> </th> <tr data-ng-repeat="item in publishers_data"> <td>{{item.a}}</td> </tr> </table> I used the following code in my e2e test: var total = 100; var sum = 0; element.all(by.repeater("item in publishers_data")).then( function(rows){ for(var i=0;i<rows.length;i++){ sum + = rows(by.model("{{item.a}}").getText()

Can't set timeout for jasmine

走远了吗. 提交于 2019-12-05 04:51:05
I've tried all the solutions in this answer but none of them work for me. I'm using jasmine v2.3.2 and jasmine-core v2.3.4 When I do this test: jasmine.DEFAULT_TIMEOUT_INTERVAL= 999999; describe('tests content controller', function(){ //... fit('/content should return 200',function(done){ request(app) .get('/content?type=script') .set('Authorization', "bearer " + requestor.token) .set('Accept', 'application/json') .expect(200) .end(function (err, res) { if (err) done.fail(err); expect(res.statusCode).toBe(200); console.log('got here'); console.log(jasmine.DEFAULT_TIMEOUT_INTERVAL); //prints

CSS issue testing AngularJS directives with Karma + Jasmine

若如初见. 提交于 2019-12-05 03:59:52
I'm using Karma + Jasmine to test my AngularJS directives, I wrote more than 300 tests and I was very happy... until I found an issue that taken me here because I'm stuck: some tests are failing because they need a CSS applied to some elements (a piece of code in my directive does a size computation based on this style), and despite I added the file containing the CSS implementation, this file seems ignored during tests. In my karma config I added the css file in this way: files: [ // .. 'styles/foo.css', // .. ], the settings above generates a link tag in the body rather than head , so I

How do you reference external libraries with Jasmine + Resharper

守給你的承諾、 提交于 2019-12-05 03:59:02
I can run Jasmine unit tests from the Resharper 8.0 unit test runner. I have a problem where any Javascript references that are normally in the html page (ie in my case Ext-Js) then I can't use the Resharper test runner, as you don't seem to have access to the HTML page that Resharper uses. (I assume it's generated as I could not locate it on disk) I was thinking if there is a way to call or load your external library references from the Javascript test file directly instead of via the html page, then I could get this to work. I've not found if that is possible with Javascript (or Ext-Js) yet.

How should I access an element's angularjs $ngModelController in a jasmine unit test?

最后都变了- 提交于 2019-12-05 03:53:10
I'm currently using directiveElement.data("$ngModelController") to get access to the element's $ngModelController , as in the following example. describe("directiveElement", function () { it("should do something with ngModelController", inject(function($compile, $rootScope) { var directiveElement = $compile("<input ng-model="myNgModel" customDirective type="text"></input>")($rootScope); $rootScope.$digest(); var ngModelCtrl = directiveElement.data("$ngModelController"); ngModelCtrl.$modelValue = "12345"; // do rest of test })); }); However, I want to know if there is a better to access the

how to test $window.open using jasmine

夙愿已清 提交于 2019-12-05 03:34:19
This is my function $scope.buildForm = function (majorObjectId, name) { $window.open("/FormBuilder/Index#/" + $scope.currentAppId + "/form/" + majorObjectId + "/" + name); }; This is my jasmine test spec it('should open new window for buildForm and with expected id', function () { scope.majorObjectId = mockObjectId; scope.currentAppId = mockApplicationId; var name = "DepartmentMajor"; scope.buildForm(mockObjectId, name); scope.$digest(); expect(window.open).toHaveBeenCalled(); spyOn(window, 'open'); spyOn(window, 'open').and.returnValue("/FormBuilder/Index#/" + scope.currentAppId + "/form/" +