Questions tagged [jasmine-jquery]

An extension to Jasmine JavaScript library for easier testing jQuery functions.

An extension to Jasmine JavaScript library for easier testing jQuery functions. Adds jQuery-specific matchers, allows loading HTML, CSS and JSON fixtures.

Links:

  1. Project page on Github
243 questions
38
votes
1 answer

How would I test a $scope.watch (AngularJS) change in Jasmine?

I've just recently started writing something with AngularJS and I'm not sure how to go about writing a test for this particular thing. I'm building a "Help Request" mode that has different states. So in my controller, I use a $scope.request_mode…
32
votes
1 answer

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

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…
Rahul R.
  • 5,965
  • 3
  • 27
  • 38
19
votes
3 answers

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

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:…
user1639431
  • 3,693
  • 8
  • 24
  • 22
15
votes
2 answers

Jasmine.js Testing - spy on window.open

JS var link = this.notificationDiv.getElementsByTagName('a')[0]; link.addEventListener('click', function (evt){ evt.preventDefault(); visitDestination(next); }, false); } var visitDestination = function(next){ …
baconck
  • 386
  • 2
  • 5
  • 19
13
votes
2 answers

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

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; …
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
12
votes
1 answer

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

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({ …
Simon
  • 2,484
  • 6
  • 35
  • 54
10
votes
1 answer

Jasmine spies not being called

I am having some trouble implimenting spying in Jasmine I want to check if a link has been clicked on a slider using a jasmine spy and jasmine jquery. Here is a simplified version: I have some links as part of an html fixture file.
jamie holliday
  • 1,617
  • 9
  • 26
  • 39
10
votes
2 answers

Jasmine test using .toHaveBeenCalledWith fails for sign-up form

The single page application I am working on has a login view with two forms: a sign-in form and a sign-up form. The following spec describes tests for these forms. I am using Jasmine-jQuery 1.4.2. // user_spec.js describe("User", function() { …
JJD
  • 50,076
  • 60
  • 203
  • 339
10
votes
2 answers

Mocha-compatible fixtures support

I am looking to convert from Jasmine tests to Mocha tests because of its ability to do Before(all), its reporting capabilities, and its support for coffeescript. One thing I haven't been able to find is whether Mocha (or in conjunction with a…
badunk
  • 4,310
  • 5
  • 27
  • 47
9
votes
1 answer

AngularJS testing using Jasmine + Karma in Visual Studio 2013

I am new to Angularjs framework and also testing it using Jasmine framework and Karma. I have a ASP.NET MVC app built with Visual Studio 2013 and I would like to include Jasmine package and Karma in order to test js. Maybe this issue is already…
studentsss
  • 197
  • 5
  • 17
9
votes
4 answers

BeforeAll and AfterAll in javascript test cases

I want do something before all tests, then after? What is the best way to organize my code? For example: backup some variables -> clear them -> test something -> restore backups. 'beforeEach' and 'afterEach' are too expencive. Thanks!
user2996905
  • 125
  • 1
  • 6
8
votes
4 answers

testing backbone.js view events with jasmine

I'm trying to implement view tests for a Coffeescript implementation of the ubiquitous backbone.js 'todo' example (see github.com/rsim/backbone_coffeescript_demo.) My jasmine tests of the above demo work pretty well, except for view events. I expect…
Lille
  • 305
  • 4
  • 14
7
votes
2 answers

How to fix function has already been spied on error in Jasmine

I have 3 tests, each testing various methods. it('test function1', function() { spyOn(document, 'getElementById'); // ... some code to test function1 expect(document.getElementById).toHaveBeenCalled(); }); it('test function2',…
Mumzee
  • 719
  • 1
  • 11
  • 25
7
votes
1 answer

jasmine-jquery won't load any fixture

I am using karma + jasmine + jquery + jasmine-jquery I have several pure js unit tests and now it's time to move on to write some html dependent tests. I tried jasmine-jquery and its loadFixtures, but no matter what I try I am still getting an…
Martin Macak
  • 3,507
  • 2
  • 30
  • 54
7
votes
1 answer

Failing to get the scrollTop value inside a Jasmine test

This is my first question to Stack Overflow and Jasmine is fairly new to me, so I hope I'm doing ok here. I have a Jasmine test where I try to set the scroll position of my page to a certain value. The actual code is pretty complex, but I managed to…
balzafin
  • 1,416
  • 1
  • 17
  • 28
1
2 3
16 17