jasmine

How to simulate mouse events in Jasmine tests in Angular 2 or 4

百般思念 提交于 2019-12-10 14:34:49
问题 I am pretty new to Jasmine testing and I am trying to test a directive which handles mouse events like mouse down, up and move. My question is how can I pass mouse coordinates from the spec of Jasmine to my directive and simulate the mouse events. I have searched a lot on this topic but I couldn't find any examples except for this one which doesn't do anything like passing the coordinates of the element. The following is my attempt to write the test using the TestBed configuration in Angular:

Jasmine.js Testing - spy on window.open

邮差的信 提交于 2019-12-10 14:29:10
问题 JS var link = this.notificationDiv.getElementsByTagName('a')[0]; link.addEventListener('click', function (evt){ evt.preventDefault(); visitDestination(next); }, false); } var visitDestination = function(next){ window.open(next) } Spec var next = "http://www.example.com" it( 'should test window open event', function() { var spyEvent = spyOnEvent('#link', 'click' ).andCallFake(visitDestination(next));; $('#link')[0].click(); expect( 'click' ).toHaveBeenTriggeredOn( '#link' ); expect( spyEvent )

jasmine.clock().tick() does not work with $timeout and debounce, but works fine with setTimeout

夙愿已清 提交于 2019-12-10 13:59:51
问题 Below I have 3 functions that do exactly the same thing. Each one uses a different way of calling setTimeout, delay1() uses setTimeout directly, delay2() uses angularjs $timeout and delay3() uses lodash debounce. They all work fine. The problems occurs when I test using Jasmine. setTimeout works fine with the jasmine.clock().tick() method, but $timeout and debounce don't I am interested in getting debounce working with Jasmine. I know I can use $timeout.flush() with angularjs but $timeout and

TypeScript compilation failure and Karma test execution?

爷,独闯天下 提交于 2019-12-10 13:58:38
问题 I'm currently using Karma + Jasmine to run the tests on my TypeScript-based project, and I want to 'break the tests' when TypeScript compilation fail in karma watch mode. I'm using standard Karma configuration and compiling TS using webpack preprocessor (which compiles TS files). Everything works perfectly fine, except that seeing all tests pass when a compilation error occurs is highly misleading (karma rerun previous tests even if webpack compilation fails). It seems rather trivial, but

Jasmine unit tests not waiting for promise resolution

杀马特。学长 韩版系。学妹 提交于 2019-12-10 13:55:20
问题 I have an angular service that has an async dependency like this (function() { angular .module('app') .factory('myService', ['$q', 'asyncService', function($q, asyncService) { var myData = null; return { initialize: initialize, }; function initialize(loanId){ return asyncService.getData(id) .then(function(data){ console.log("got the data!"); myData = data; }); } }]); })(); I want to unit test the initialize function and I'm trying in jasmine like this: describe("Rate Structure Lookup Service"

Jasmine expect(resultCode).toBe(200 or 409)

ⅰ亾dé卋堺 提交于 2019-12-10 13:23:27
问题 For some test scenarios I run into the need of testing against multiple values which are all OK. What I would like to do is something as follows: expect(resultCode).toBeIn([200,409]); This spec should pass when resultCode is either 200 or 409 . Is that possible? ADDED Thanks to peter and dolarzo for pointing me towards creating matchers. I had problems with addMatchers(). So, in the end I added the following to the jasmine.js: jasmine.Matchers.prototype.toBeIn = function (expected) { for (var

Can't get $.ajax.mostRecentCall to work with jasmine 2.0.2

点点圈 提交于 2019-12-10 12:34:23
问题 Having real trouble getting a simple example to work. I am using this example taken from https://gist.github.com/Madhuka/7854709 describe("Test for spies", function() { function sendRequest(callbacks, configuration) { $.ajax({ url: configuration.url, dataType: "json", success: function(data) { callbacks.checkForInformation(data); }, error: function(data) { callbacks.displayErrorMessage(); }, timeout: configuration.remainingCallTime }); } it("should make an Ajax request to the correct URL",

jasmine.js expect() does not work inside an asynchronous callback

匆匆过客 提交于 2019-12-10 12:30:02
问题 I'm getting acquainted with Jasmine (http://pivotal.github.com/jasmine/) and found something rather baffling: it("should be able to send a Ghost Request", function() { var api = fm.api_wrapper; api.sendGhostRequest(function(response) { console.dir('server says: ', response); }); expect(true).toEqual(false); }); Fails as expected. However, moving the expect call inside the callback: it("should be able to send a Ghost Request", function() { var api = fm.api_wrapper; api.sendGhostRequest

Allure reports are not generated in Protractor

混江龙づ霸主 提交于 2019-12-10 12:02:44
问题 I included the below code in my conf.js file but the Allure reports are not getting generated. onPrepare : function() { var AllureReporter = require('jasmine-allure-reporter'); jasmine.getEnv().addReporter( new AllureReporter({ allureReport : { resultsDir : 'allure-results' } }) ); jasmine.getEnv().afterEach(function(done) { browser.takeScreenshot().then(function(png) { allure.createAttachment('Screenshot', function() { return new Buffer(png, 'base64') }, 'image/png')(); done(); }) }); }

I can't get right elements

喜欢而已 提交于 2019-12-10 12:01:55
问题 I click the sort button, get all prices, and I need to ensure that elements were sorted correctly by prices. So I need to get price value="377", price value="1288", price value="1688" etc. but I can't get the right elements. <div class="ssl-price-box"> <price value="377" units="/yr" class="lg-price ng-isolate-scope"> <span class="price"> <span class="currency-icon">$</span> <span class="integer ng-binding">3.</span> <span class="cent ng-binding">77</span> <span class="units">/yr</span> </span