jasmine

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); }

Protractor: Find Element by Attribute

天涯浪子 提交于 2019-12-30 08:00:28
问题 I have the following element i need to find for testing: <div class="alert alert-danger" role="alert" ng-show="notValid">Zugangsdaten eingeben</div> How can i find this element to check visibility (ng-show)? The ng-show attribute and value are the only attribute and value to identify the element uniquely. The class is used in many elements... I am searching for something like: var notValid = element(by.Attribute('ng-show', 'notValid'); 回答1: You can find it by.css(): element(by.css('div[ng

Stubbing WebSocket in JavaScript with Jasmine

≡放荡痞女 提交于 2019-12-30 04:50:05
问题 I try to test if onmessage is a proper function. Here is a test: describe(".init(address, window)", function() { beforeEach(function() { address = 'ws://test.address'; window = {}; e = { data: {} } spyOn(window, 'WebSocket').and.returnValue(function() {return {onmessage: null}}); spyOn(subject, 'handleMessage'); }); it("should create a WebSocket client which connects to the given address", function() { subject.init(address, window); expect(window.WebSocket).toHaveBeenCalledWith(address); });

How can I get my jasmine tests fixtures to load before the javascript considers the document to be “ready”?

我是研究僧i 提交于 2019-12-30 03:55:08
问题 I am fairly certain that the issue is that the jquery bindings set to run on $(document).ready do not have the fixture html available to them. So when my events occur that are intended to make a change to the DOM via a jquery function, nothing happens, and my tests fail. I saw a "solution" to this problem here, but that solution which did work for me, required changing my working jquery function to bind with the .live method instead of the .click method. I have two issue with this. First I do

Testing backbone.js application with jasmine - how to test model bindings on a view?

白昼怎懂夜的黑 提交于 2019-12-29 16:24:32
问题 I had some interesting tribulations in trying to test whether views were correctly bound to events. In backbone, we typically bind to events in the initialize method, using something along the lines of: something.bind("change", this.render); . In my test, I want to make sure that this binding is set up, so I did the following: this.myView = new MyView(); spyOn(this.myView, "render");; this.legendView.groupData.trigger("change"); expect(this.legendView.render).toHaveBeenCalled(); But, that won

Is there a way to run particular Protractor test depending on the result of the other test?

假如想象 提交于 2019-12-29 10:02:48
问题 This kind of question has been asked before but most of this question has pretty complicated background. The scenario is simple. Let's say we are testing our favorite TODO app. Test cases are next: TC00 - 'User should be able to add a TODO item to the TODO list' TC01 - 'User should be able to rename TODO item' TC02 - 'User should be able to remove TODO item' I don't want to run the TC01 and TC02 if TC00 fails (the TODO item is not added so I have nothing to remove or rename) So I've been

Is there a way to run particular Protractor test depending on the result of the other test?

允我心安 提交于 2019-12-29 10:02:26
问题 This kind of question has been asked before but most of this question has pretty complicated background. The scenario is simple. Let's say we are testing our favorite TODO app. Test cases are next: TC00 - 'User should be able to add a TODO item to the TODO list' TC01 - 'User should be able to rename TODO item' TC02 - 'User should be able to remove TODO item' I don't want to run the TC01 and TC02 if TC00 fails (the TODO item is not added so I have nothing to remove or rename) So I've been

Doing something aftereach describe in protractor with selenium server with angularjs

♀尐吖头ヾ 提交于 2019-12-29 09:19:12
问题 I want to do something after each describe(not after each testcase) and before each describe, is there any way to do this? I have tried below format, but it gives me error that, before and after not defined, is it possible to do sometask before and after of each describe: describe('testcase', function () { before(function () { -------------- }) beforeEach(function () { ----------------- }) afterEach(function () { -------------- }) after(function () { ----------------- }) it('task1', function

Running jasmine tests for a component with NgZone dependency

家住魔仙堡 提交于 2019-12-29 08:41:07
问题 How would I go ahead with running a jasmine test for the following component: @Component({ moduleId: module.id, selector: "testComp", template: "<div>{{value}}</div>", }) export class TestComp { public value: string = "This is me"; constructor(public zone: NgZone) { this.zone.run(() => console.log("zone is here")); } } The following fails with the Can't resolve all parameters for NgZone: describe("test", () => { let fixture; let component; beforeEach(async(() => { TestBed

Karma + Jasmine: Cannot read property 'getComponentFromError'

天大地大妈咪最大 提交于 2019-12-29 07:42:40
问题 I am following this tutorial: https://angular.io/guide/testing#component-test-scenarios for karma+jasmine unit testing. Here my code: import { AppComponent } from "./app.component"; import { ComponentFixture, TestBed } from "@angular/core/testing"; describe('AppComponent', () => { let component: AppComponent; let fixture: ComponentFixture<AppComponent>; let h1: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ declarations: [ AppComponent ], }); fixture = TestBed