jasmine

Jasmine tests pass in Chrome and Firefox but fail with PhantomJS

隐身守侯 提交于 2019-12-22 05:51:13
问题 I am building a basic blogging app with React. I am using Jasmine and Karma to run my front end tests. I got my first test up and running and it passes in Chrome (Chromium) and Firefox, but when it runs in PhantomJS I get the following error: PhantomJS 1.9.8 (Linux 0.0.0) ERROR TypeError: 'undefined' is not a function (evaluating 'ReactElementValidator.createElement.bind( null, type )') at /home/michael/repository/short-stories/test/karma_tests/story_test.js:1742 My test file looks like this:

Trying to spy (Jasmine) on Array.prototype methods causes stack overflow

两盒软妹~` 提交于 2019-12-22 05:41:51
问题 This is pretty odd. Using the testem runner with jasmine2 and the following spec executes (though it correctly flags that there are no expectations): describe('Spying on array.prototype methods', function(){ it('should work this way', function(){ spyOn( Array.prototype, 'push' ).and.callThrough(); // expect(1).toBe(1); }); }); However, add an expect (any expect !) and it causes the stack to overflow with the following message in the testem console: RangeError: Maximum call stack size exceeded

How do you spy on AngularJS's $timeout with Jasmine?

浪尽此生 提交于 2019-12-22 05:41:11
问题 I am trying to spy on $timeout so that I can verify that it has not been called. Specifically, my production code (see below) calls $timeout as a function, not an object: $timeout(function() { ... }) and not $timeout.cancel() // for instance Jasmine, however, requires an object to be spied upon, like this: spyOn(someObject, '$timeout') I don't know what 'someObject' would be though. I am using Angular mocks, if that makes any difference. Edit: The relevant production code I'm trying to test

Cannot read property 'injector' of null jasmine angular 2

我只是一个虾纸丫 提交于 2019-12-22 04:46:16
问题 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

Protractor wait command is not able to wait for the bootstrap modal to appear

那年仲夏 提交于 2019-12-22 04:18:27
问题 Scenario: Whenever user sign in using incorrect credentials, a bootstrap modal appears for 1-2 second with message "sorry, incorrect credentials". Below is the HTML of the modal. <div class="modal-content"> <div class="modal-body note-error text-center ng-binding"> Sorry, invalid credentials! </div> </div> I need to verify if the expected error text is equal to actual error text. My code PageObject.js var errorModal = element(by.css('.modal-body.note-error.text-center.ng-binding')); this

spyOn could not find an object to spy upon for start()

心已入冬 提交于 2019-12-22 04:14:19
问题 I am using angular-cli testing framework. inside my component , I have used 'ng2-slim-loading-bar' node module. submit(){ this._slimLoadingBarService.start(() => { }); //method operations } Now when I am testing this component, I have applied spyOn this service as : beforeEach(() => { let slimLoadingBarService=new SlimLoadingBarService(); demoComponent = new DemoComponent(slimLoadingBarService); TestBed.configureTestingModule({ declarations: [ DemoComponent ], providers: [ { provide:

How to stub require() / expect calls to the “root” function of a module?

 ̄綄美尐妖づ 提交于 2019-12-22 04:13:10
问题 Consider the following jasmine spec: describe("something.act()", function() { it("calls some function of my module", function() { var mod = require('my_module'); spyOn(mod, "someFunction"); something.act(); expect(mod.someFunction).toHaveBeenCalled(); }); }); This is working perfectly fine. Something like this makes it green: something.act = function() { require('my_module').someFunction(); }; Now have a look at this one: describe("something.act()", function() { it("calls the 'root' function

How to test AngularJS Directive with scrolling

纵饮孤独 提交于 2019-12-22 04:07:29
问题 I have an infinite scroll directive that I am trying to unit test. Currently I have this: describe('Infinite Scroll', function(){ var $compile, $scope; beforeEach(module('nag.infiniteScroll')); beforeEach(inject(function($injector) { $scope = $injector.get('$rootScope'); $compile = $injector.get('$compile'); $scope.scrolled = false; $scope.test = function() { $scope.scrolled = true; }; })); var setupElement = function(scope) { var element = $compile('<div><div id="test" style="height:50px;

how to test $window.open using jasmine

萝らか妹 提交于 2019-12-22 04:06:56
问题 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,

CSS issue testing AngularJS directives with Karma + Jasmine

岁酱吖の 提交于 2019-12-22 04:04:35
问题 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: [ // ..