jasmine-jquery

Error on Jasmine - Expected event click to have been triggered on #DIV_ID

久未见 提交于 2019-12-01 10:22:15
问题 I am referred this link to trigger a event when developing a testing tool in Jasmine framework: http://www.htmlgoodies.com/beyond/javascript/js-ref/testing-dom-events-using-jquery-and-jasmine-2.0.html I am trying to get the newly applied CSS attribute after triggering a click event on #DIV_ID in Jasmine framework. I am tried this code: spyEvent = spyOnEvent('#DIV_ID', 'click'); $('#DIV_ID').trigger( "click" ); expect('click').toHaveBeenTriggeredOn('#DIV_ID'); expect(spyEvent)

How to assert a spy is invoked with event on click using jasmine?

不问归期 提交于 2019-11-30 14:47:27
问题 I'm writing a simple click handler and need the event passed in (like so) Thing = function($){ var MyObject = function(opts){ this.opts = opts; }; MyObject.prototype.createSomething = function(){ var that = this; $('#some_dom_element').live('click', function(e) { that.doStuff(e); }); }; MyObject.prototype.doStuff = function(e) { //do some javascript stuff ... e.preventDefault(); }; return MyObject; }(jQuery); Currently in my jasmine spec I've got something to spy on the function I expect gets

How do I add DOM elements in jasmine tests without using external html files?

此生再无相见时 提交于 2019-11-30 06:42:01
I'm writing some simple jasmine tests and I'm getting an exception since the code I'm testing is looking for a form that doesn't exist because there's no DOM when testing a js file only: $("form")[0] in the tested js file leads to: TypeError: $(...)[0] is undefined I read a bit about jasmine-jquery and realized I can use some html fixture with an external html file. That flow seems quite messy, since all I need to do is only to add an empty valid form so that the test (which focusing on something else) will run, something like <form></form> appending would be enough I think. At first I thought

How do I add DOM elements in jasmine tests without using external html files?

拜拜、爱过 提交于 2019-11-29 06:21:09
问题 I'm writing some simple jasmine tests and I'm getting an exception since the code I'm testing is looking for a form that doesn't exist because there's no DOM when testing a js file only: $("form")[0] in the tested js file leads to: TypeError: $(...)[0] is undefined I read a bit about jasmine-jquery and realized I can use some html fixture with an external html file. That flow seems quite messy, since all I need to do is only to add an empty valid form so that the test (which focusing on

How to resolve $q.all promises in Jasmine unit tests?

女生的网名这么多〃 提交于 2019-11-27 20:03:29
My controller has code like below: $q.all([qService.getData($scope.id), dService.getData(), qTService.get()]) .then(function (allData) { $scope.data1 = allData[0]; $scope.data2 = allData[1]; $scope.data3 = allData[2]; }); And in my unit tests i am doing something like this: beforeEach(inject(function($rootScope, $q, $location){// and other dependencies... qServiceSpy = spyOn(_qService, 'getData').andCallFake(function () { var data1 = { id: 1, sellingProperty: 1, }; var d = $q.defer(); d.resolve(data1); return d.promise; }); dServiceSpy = spyOn(_dService, 'getData').andCallFake(function () {

How to resolve $q.all promises in Jasmine unit tests?

ε祈祈猫儿з 提交于 2019-11-26 20:08:11
问题 My controller has code like below: $q.all([qService.getData($scope.id), dService.getData(), qTService.get()]) .then(function (allData) { $scope.data1 = allData[0]; $scope.data2 = allData[1]; $scope.data3 = allData[2]; }); And in my unit tests i am doing something like this: beforeEach(inject(function($rootScope, $q, $location){// and other dependencies... qServiceSpy = spyOn(_qService, 'getData').andCallFake(function () { var data1 = { id: 1, sellingProperty: 1, }; var d = $q.defer(); d