jasmine-jquery

Do you need spies to test if a function has been called in Jasmine?

我是研究僧i 提交于 2020-12-13 03:02:23
问题 Am learning Jasmine, wondering if the following test would be valid? And if not, can someone explain why? I've been reading a number of tutorials and can't find a good explanation that has helped me understand why I can't seem to write a test like the one below correctly. // spec describe("when cart is clicked", function() { it("should call the populateNotes function", function() { $("#show-cart").click() expect(populateNotes()).toHaveBeenCalled(); }) }) // code $("#show-cart").click(function

Testing focus() on an element in an AngularJS directive template

戏子无情 提交于 2020-01-24 03:50:46
问题 Given the following directive directive('myDirective', function() { return { restrict: 'A', scope: {}, replace: false, template: '<input ng-focus="onFocus()" type="text" />', link: function(scope, element, attr) { scope.onFocus = function() { console.log('got focus'); }; } }; }); I've tested that the focus watcher works in a browser, but I'd like to be able to trigger it in a unit test. This is what I've tried but it isn't working. var element = angular.element('<div my-directive></div>');

Jasmine spies not being called

笑着哭i 提交于 2019-12-30 08:16:09
问题 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. <a href="#" class="someLink">Link 1</a> <a href="#" class="someLink">Link 2</a> slider: var Slider = function(links){ this.sliderLinks = $(links); this.bindEvents(); } Slider.prototype.bindEvents = function(){ this.sliderLinks.on('click', this.handleClick); }

Why is the jQuery code not executing, or at least not appearing to execute, in my jasmine test?

ⅰ亾dé卋堺 提交于 2019-12-25 00:55:56
问题 I am running Rails 3.2.8 with the jasmine-rails gem. Here are the lines from my Gemfile describing the jasmine set-up: jasmine (1.2.1) jasmine-core (>= 1.2.0) rack (~> 1.0) rspec (>= 1.3.1) selenium-webdriver (>= 0.1.3) jasmine-core (1.2.0) jasmine-headless-webkit (0.8.4) coffee-script jasmine-core (~> 1.1) multi_json rainbow sprockets (~> 2) jasmine-rails (0.1.0) jasmine jasmine-headless-webkit rails (>= 3.1.0) I am also using the jasmine-jquery extension. This set of functions provide the

Angular6 Jasmine TypeError: expect(…).toBeVisible is not a function

霸气de小男生 提交于 2019-12-24 05:07:05
问题 Setting up jasmine-query-matches in angular6 On angular 5 project it looks at simple as import { } from 'jasmine-jquery/lib/jasmine-jquery'; import { } from 'jasmine-jquery-matchers'; import * as $ from 'jquery'; On angular 6 i have tried the following import {} from "jasmine-jquery/lib/jasmine-jquery" ; import {} from "jasmine-jquery-matchers/dist/jasmine-jquery-matchers" ; import { } from "karma-jasmine-jquery"; import * as $ from 'jquery'; OR import {} from "jasmine-jquery" ; import {}

jasmine-jquery fixtures not loading

蹲街弑〆低调 提交于 2019-12-23 18:19:29
问题 Problem is that jasmine-jquery in not loading my fixtures from spec/fixtures folder. Now when I look at jasmine-jquery source code default path for fixtures is spec/javascripts/fixtures . In a version that I have, there is no spec/javascripts/fixtures folder. It seems it is something for Ruby gem. I also tried to create that javascripts folder but still it can't load it. When I place my fixture fragment inside of SpecRunner.html body - it works. Here is my html fragment: <ul class="fr"> <li><

Jasmine-jQuery loadFixtures is not defined

旧城冷巷雨未停 提交于 2019-12-23 17:47:15
问题 I'm still new to the whole jasmine things and in past few hours I stuck in this problem. I tried to load an external fixture file using loadFixture(). I use Jasmine 2.0.0 and Jasmine-jQuery 2.0.5. ReferenceError: loadFixtures is not defined at Suite.<anonymous> (--appname--/app/assets/Tester/spec/ChannelSpec.js:5:6) at Env.describe (--appname--/app/assets/Tester/lib/jasmine-2.0.0/jasmine.js:613:25) at jasmineInterface.describe (--appname--/app/assets/Tester/lib/jasmine-2.0.0/boot.js:37:18) at

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

我的梦境 提交于 2019-12-21 03:08:12
问题 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 variable. The different links to activate help requests set that variable to something differently. Then inside my directive, I'm doing a $scope.$watch('request_mode', function(){...}); to selectively activate or deactivate things as the request mode

jQuery trigger('click') not working with Jasmine-jquery

旧街凉风 提交于 2019-12-17 20:29:32
问题 This is my test code: describe("Login", function(){ beforeEach(function(){ loadFixtures('login-fixture.html'); }) it("should enable the button when checking 'remember password'", function(){ $('#remember').trigger('click'); expect($('#keepIn')).not.toBeDisabled(); }); }); And this is my production code: $(document).ready(function(){ $('#remember').click(function(e) { if($('#remember').is(':checked')) { $('#keepIn').removeAttr('disabled'); } }); }); This is not working, the production code

Jasmine - trigger event not working

橙三吉。 提交于 2019-12-11 18:55:02
问题 Code that I'm trying to test: $(".toggle_item").on("change", function() { console.log("change triggered") item_name = $(this).data("name"); value = $(this).prop("checked"); if (Item.isValid(item_name) && cartModule.isUnique(item_name)) { cartModule.toggleItem(item_name, value); } }) Jasmine spec: describe("changing toggle item", function() { beforeEach(function() { console.log("in spec") affix(".toggle_item[data-name='ladder']") spyOn(cartModule, "isUnique") spyOn(Item, "isValid") $(".toggle