jasmine

How to test JavaScript with DOM elements using jasmine?

只谈情不闲聊 提交于 2019-12-04 15:04:45
I am trying to write a test in jasmine for JavaScript code including DOM elements which doesn't work. It works when I test only for JavaScript code (just simple functions but not for DOM elements). I have been researching for so long and can't really find the answer. I also tried to use jsdom as it's supposed to be used when testing for DOM elements, however I keep getting a bunch of errors. Is there any 'easy' way to test DOM elements only using jasmine? JavaScript: var result; var adding = function(one, two) { var one1 = document.forms["myForm"]["one"].value; var two1 = document.forms[

Angular testing submit event on reactive form

一曲冷凌霜 提交于 2019-12-04 15:03:30
问题 Context I have a component with a basic form (reactive form). I try to test the submit event on this form to see if it calls the necessary method properly. My problem I can't trigger the submit event of the form Files Component.html <form class="form-horizontal" id="staticForm" [formGroup]="mySimpleForm" (ngSubmit)="sendMethod();" > <input type="text" formGroupName="email"> <button type="submit">Send form</button> </form> Component.ts ngOnInit() { this.initSimpleForm(); } private

Testing Web Sockets with Jasmine

坚强是说给别人听的谎言 提交于 2019-12-04 14:08:22
问题 Here is some code that has been written for web-socket using stomp protocol. function WS(url) { var ws = new SockJS('/notifications'); this.client = Stomp.over(ws), this.client.connect('', '', function() { console.log('Connected'); }, function(error) { console.log('STOMP protocol error: ', error.headers.message); }); } WS.prototype.disconnect = function() { }; WS.prototype.subscribe = function() { }; WS.prototype.unSubscribe = function() { }; WS.prototype.send = function(msg) { }; I found

How to spy on anonymous function using Jasmine

一笑奈何 提交于 2019-12-04 13:14:22
问题 I'm using Jasmine to test my angular application and want to spy on an anonymous function. Using angular-notify service https://github.com/cgross/angular-notify, I want to know whether notify function have been called or not. Here is my controller: angular.module('module').controller('MyCtrl', function($scope, MyService, notify) { $scope.isValid = function(obj) { if (!MyService.isNameValid(obj.name)) { notify({ message:'Name not valid', classes: ['alert'] }); return false; } } }); And here is

protractor timeout after 30000msec

送分小仙女□ 提交于 2019-12-04 12:57:07
I am tryin to integrate protractor e2e tests in my cruisecontrol I am using the following testspec: describe('index', function () { var ptor; it('should have a title', function () { browser.get('http://juliemr.github.io/protractor-demo/'); expect(browser.getTitle()).toEqual('Super Calculator'); }); it('Check google', function () { browser.driver.get('http://www.google.com'); }) }); When I run this spec though the command line works fine. However when I run it as a nant target in the build config it says there is a timeout error: 31mtimeout: timed out after 30000 msec waiting for spec to

Using $injector in AngularJS when integration testing (without using ngMock)

◇◆丶佛笑我妖孽 提交于 2019-12-04 12:47:36
I'm needing to setup some integration tests in AngularJS using Karma/Jasmine but having trouble, because when not using ngMock (since I want to hit the actual $http endpoints), there are no module or inject methods. So how do I inject services into my tests? I've tried angular.injector.invoke(...) but can't get it working, always comes back with an error like Unknown provider: AuthServiceProvider <- AuthService . Thoughts? Try this 'use strict'; describe('Login User', function () { var app, LoginService; beforeEach(module('app')) ; beforeEach(inject(function(_LoginService_) { LoginService =

Can the time out issue be the consequence of browser.sleep() and browser.waitForAngular?

冷暖自知 提交于 2019-12-04 12:39:01
In protractor scripts i'm always having problem of time out, even if i put a big time out jasmine interval , allscripttimeout ... And in some places i'm obliged to wait until element are present like in home page until the url is totally loaded. Can the time out issue be the consequence of browser.sleep(time_ms); browser.waitForAngular(); If so, how can i fix this problem ? Here the problem in details Thanks, Yes they could be -- browser.sleep() would only timeout if you had it sleep longer than your Jasmine timeout interval (default is 30 seconds). browser.waitForAngular() is automatically

How to make HTTP GET+POST request in Protractor

≡放荡痞女 提交于 2019-12-04 12:19:48
问题 I am facing problem to send HTTP get request in Protractor. Actually, I need to check data in DB after perform some action in UI. It will be very helpful if I will be able to do it using JQuery, but I am not able to find a way how to use JQuery inside Protractor. Need Help !! Actually, we did try to use the Node.js lib as shown below, but facing problems in it. var http = require('http'); var json_data; http.get('SiteUrl', function(response) { var bodyString = ''; response.setEncoding('utf8')

jasmine-node shows error when ran from command prompt

风流意气都作罢 提交于 2019-12-04 12:04:44
Installed jasmine-node using this: sudo npm install jasmine-node -g It is successful and shows: /usr/bin/jasmine-node -> /usr/lib/node_modules/jasmine-node/bin/jasmine-node jasmine-node@1.14.3 /usr/lib/node_modules/jasmine-node ├── underscore@1.6.0 ├── mkdirp@0.3.5 ├── walkdir@0.0.7 ├── jasmine-reporters@2.0.0 ├── coffee-script@1.7.1 ├── requirejs@2.1.14 ├── jasmine-growl-reporter@0.0.3 (growl@1.7.0) └── gaze@0.3.4 (minimatch@0.2.14, fileset@0.1.5) But when I try to run this: $ jasmine-node spec/ or jasmine-node it shows the error like this: /usr/lib/node_modules/jasmine-node/lib/jasmine-node

Angularjs - how to unit test form validation

笑着哭i 提交于 2019-12-04 11:23:43
I'm using Jasmine to unit test my Angular App. How can I test form validation in my controller? For example, I have a login function: $scope.login = function() { if($scope.form_login.$valid) { //send request with username and password }; }; I'm trying to set $valid to true , but I can't access the form here. I got an error TypeError: Cannot set property '$valid' of undefined : it('should not send request if form validation fails', function() { $controller('loginController', {$scope: $scope}); $scope.form_login.$valid = true; $scope.login(); }) Alex Ryltsov Unit test should not really test the