jasmine

Jasmine: How to mock MutationObserver?

天涯浪子 提交于 2019-12-23 07:17:07
问题 I have a angularjs component, HTML template <div id="panel" class="hide-div"> <div id="viewPort" class="hide-div"> ... </div> </div> JS var myController = function() { var ctrl=this; ctrl.$onchanges = function() { } var source = $("#viewport"); var target = $("#panel"); var observer = new MutationObserver(function() { target.toggleClass("hide-div", source.hasClass("hide-div")); }); observer.observe($("#viewport")[0], {attributes: true}); } var config = { controller: [myController],

How jasmine clock works?

天涯浪子 提交于 2019-12-23 07:09:00
问题 I don't want to read code for hours to find the relevant part, but I am curious how jasmine implements its clock. The interesting thing with it is that it can test async code with sync testing code. AFAIK, with the current node.js, which supports ES5, this is not possible (async functions are defined in ES7). Does it parse the js code with something like estraverse and build an async test from the sync one? Just an example of what I am talking about: it("can test async code with sync testing

How to click a button in row in a table using protractor js

你离开我真会死。 提交于 2019-12-23 05:23:29
问题 I am writing protractor test cases. I want to click on edit button. When I am checking by id it is not found. Code: <table class="table table-bordered table-hover"> <thead> <tr> <th>Code</th> <th>Start Date</th> <th></th> </tr> </thead> <tbody> <tr ng-repeat="batch in batches.list"> <td><a ui-sref="root.courses.detail.batches.assessments({ batch_id: batch.id,assessment_status: 'published'})">BID00{{batch.id}}</a></td> <td>{{batch.start_date}}</td> <td> <button id="edit" type="button" class=

angularjs jasmine tests: Variable vm not found

走远了吗. 提交于 2019-12-23 05:11:27
问题 New to angular and Jasmine tests in angular. So I am writing a sample unit test to test a length of an array upon initialization in my controller. I expect the array to be of length 0. However, not sure what I am missing, the test output says that it cannot find the variable vm I am using to refer to the array. Here is my test: (function(){ 'use strict'; describe('Testing UploadedReleasesController', function() { beforeEach(module('app.uploadedReleases')); describe('Testing uploaded releases

“setNetworkConditions” in protractor e2e tests says not a function

僤鯓⒐⒋嵵緔 提交于 2019-12-23 04:58:19
问题 I am trying to use the driver.setNetworkConditions({ offline : true }); in my code, but it says that Failed: _protractor.browser.driver.setNetworkConditions is not a function . Here is my code to access it. import { browser } from 'protractor'; describe('disable browser network', () => { "use strict"; let browserA = browsers.a; it('should disable chrome network', () => { browserA.ignoreSynchronization = true; browser.driver.setNetworkConditions({ offline: true }); //..... my other

protractor + cucumber - element not visible even though element is visible

为君一笑 提交于 2019-12-23 03:52:12
问题 this.When(/^the user clicks on login button$/, function () { return browser.wait(wagLoginPage.loginPage.signIn.isPresent().then(function (visible) { if(visible){ console.log("element is visible !!!!!!!"); wagLoginPage.loginPage.signIn.click().then(function(){ expect(visible).to.be.true; }); } else{ expect(visible).to.be.true; } }, function () { chai.assert.isFalse(true, "SingIn is not visible!") })); }); My test randomly fails in the above step. For the above code, in console window

Why my AngularJS async test in Jasmine 1.3.x is not working?

廉价感情. 提交于 2019-12-23 03:43:10
问题 Hi I have a feature complete web-app written using AngularJS (1.5.11) and now I'm getting started with unit testing using karma (0.12.37), grunt-karma (0.8.3), karma-chrome-launcher (0.1.12), karma-phantomjs-launcher (1.0.4), phantomjs-prebuilt (2.1.14), jasmine-promise-matchers (2.3.0) and karma-jasmine (0.1.6), with a 1.3.x Jasmine version. I'm not very confident in testing asynchronous stuff, so I started googling around and I always end up seeing the only mandatory thing to run AngularJS

Why does chaining selectors in Protractor return false when using isPresent

馋奶兔 提交于 2019-12-23 03:22:11
问题 So I'm writing automation tests for Ionic 2/Angular 2 and I have DOM element that looks like this <ion-segment-button class="segment-button segment-activated" role="button" tappable="" value="orders" aria-pressed="true"> and I've created a page object that looks like this: ordersButton: element(by.css('[value="orders"]')), and in my spec file my test step looks like so expect((orders.header.ordersButton).element(by.css('.segment-activated')).isPresent()).toBeTruthy(); this returns false and I

unit testing angular service, beforeEach inject doesn't execute

两盒软妹~` 提交于 2019-12-23 03:00:57
问题 I'm trying to write unit tests for an angular service with jasmine/karma. I have a similar service test, which works just fine. But this one has some additional dependencies, is in a different module and just doesn't find the service with the inject. The service looks something like this. bService is in the same module, but commonFactory and commonService are in another module, say commonModule . (function () { 'use strict'; angular .module('myService') .service('aService', aService);

Unit-testing ngResource $save

天涯浪子 提交于 2019-12-23 02:43:10
问题 I have a resource which wraps a RESTful API. I use that resource from my controller to create new objects and save them, similar to this snippet from the Angular docs: var newCard = new CreditCard({number:'0123'}); newCard.name = "Mike Smith"; newCard.$save(); When writing a unit test in Jasmine, I get the following error when the $save call is executed: "Cannot read property '$promise' of undefined". What's the best approach to testing the method in my controller which contains the above