jasmine

How do I test a form submit in Jasmine?

感情迁移 提交于 2019-12-05 14:43:47
问题 I have a form that does some extensive Javascript stuff before finally POSTing to it's ACTION URL. I am writing some Jasmine unit tests and want to make sure the Javascript stuff happens when the form is submitted. However, I definitely don't want the page to go to the ACTION URL while I am unit testing. I saw what seemed like a good suggestion here: http://groups.google.com/group/jasmine-js/browse_thread/thread/a010eced8db17c1a?pli=1 ...but, as I am fairly new to Jasmine, I am unsure how to

How to test XMLHttpRequest with Jasmine

狂风中的少年 提交于 2019-12-05 14:25:52
问题 How can I test the onreadystatechange on XMLHttpRequest or pure Javascript AJAX without jQuery? I'm doing this because I'm developing Firefox extension. I guess I have to use spies, but couldn't figure out how because my ajax won't return anything. submit : function() { var url = window.arguments[0]; var request = new XMLHttpRequest(); request.open("POST", 'http://'+this.host+'/doSomething', true); request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.send(

Chutzpah running Jasmine in TFS 2012 can't find referenced file under test

帅比萌擦擦* 提交于 2019-12-05 14:13:33
I am using Chutzpah to run our Jasmine tests. I have added the Chutzpah dlls to the solution and updated the build to run *.js tests. The project structure is as follows: MyApp.Web Scripts App Home DateControl.js MyApp.Web.Tests Scripts Jasmine lib Chutzpah (dlls) Spec App Home DateControlSpecs.js The Jasmine test file uses a reference tag to reference the file to be tested /// <reference path="../../../../../../App.web/scripts/app/home/datecontrol.js" /> The Jasmine tests are run however I get the following error: ReferenceError: Can't find variable: dateControl in file dateControl is the

Writing a log file for Protractor/Jasmine tests without using command line

帅比萌擦擦* 提交于 2019-12-05 14:01:44
I'm aware that if you were to do something like protractor config.js > file.log all the console output would be written to file.log. Is there a way to do this/access that output from within the tests though so that I can use a dynamic path that's created with my reporting tool? And also in a way that I don't lose the console output. Edits: To elaborate a little further, I'm not only interested in console.log output. I'm interested in everything that comes from what seems to be protractors testLogger . For example, at the end of a suite's execution I am presented with: [13:19:37] I/launcher - 0

How to you test an angularjs module defined inside an IIFE with jasmine?

独自空忆成欢 提交于 2019-12-05 13:47:15
how do I test this module on jasmine ? The problem is that it's very difficult to test the $controller because the function is hidden inside a closure, it’s very difficult to test them. In other words, given the module definition below, writing a unit test for MainCtrl seems impossible. (function () { 'use strict'; angular.module('app', []); function MainCtrl() { var mc = this; mc.obj = { val : 50 }; } angular.module('app').controller('MainCtrl', MainCtrl); } () ); and the "typical" jasmine test describe('app', function(){ beforeEach(module('app')); it('should create an objet with val 50',

Angular/Jasmine testing with deffered promises

和自甴很熟 提交于 2019-12-05 13:22:27
I am testing a controller using a combination of angular and jasmine, and am not completely sure about using deffered promises. This is my spec code. describe('Controller Tests', function(){ var scope, searchAPI; beforeEach(function(){ var mockSearchAPI = {}; module('myApp', function($provide){ $provide.value('searchAPI', mockSearchAPI); }); }); inject(function($q){ var testData = {"message":"hi"}; mockSearchAPI.executeSearch = function(){ var defer = $q.defer(); defer.resolve(testData); return defer.promise; }; }); beforeEach('Main Search Controller Tests', function(){ function($controller,

Executing Typescript Jasmine tests via Webpack (Terminal) to test Angular2

吃可爱长大的小学妹 提交于 2019-12-05 13:21:56
Currently I'm trying to get Jasmine to run along with Webpack, to execute tests written in typescript to test Angular2 Apps in the Terminal. I researched yesterday which packages are available for testing, and while angular2 has their own approach *1 , I looked for other tools than the recommended jasmine-core or jasmines native package jasmine . I found jasmine-node which is outdated for 2 years now. Currently investigating the Webpack+Angular2 with Jasmine testing package *2 After reading Become a Ninja with Angular2 *3 by Ninja Squad I have no satisfying information on how to combine the 3

Unit test with spy is failing. Says spy was never called

天涯浪子 提交于 2019-12-05 13:06:29
This is the code I'm testing eventsApp.factory('userData', ['userResource', function(userResource){ return{ getUser: function(userName, callback){ return userResource.get({userName:userName}, function(user){ if(callback) callback(user); }); }; }]); And this is the Jasmine test for it describe('userData', function(){ var mockUserResource; beforeEach(module('eventsApp')); beforeEach(function(){ mockUserResource = {get: function(){} }; module(function($provide){ $provide.value('userResource', mockUserResource); }); }); it('should make a call to userResource.get with provided userName', inject

Why should I mock HTTP requests inside unit tests?

牧云@^-^@ 提交于 2019-12-05 13:03:04
I'm working on a project and we've begun to write Jasmine unit tests. This application, like any good JS app does a lot of asynchronous fetching of data. I see that angular provides $httpBackend to mock up an HTTP request. I've also read and heard that it's a bad idea to test AJAX requests in your controller, and thus the raison d'etre for $httpBackend. Why is it not a good idea to test AJAX calls? How do big JS applications get around this fact? When does the actual testing of hitting the actual servers happen? Asserting that you shouldn't be testing the server from Jasmine is an overly

RequireJS not loading modules properly using karma and typescript

倖福魔咒の 提交于 2019-12-05 13:00:27
I am trying to set up unit testing for a SPA using karma/jasmine First of all, the following test runs just fine in karma: /// <reference path="../../definitions/jasmine/jasmine.d.ts" /> /// <reference path="../../src/app/domain/core/Collections.ts"/> define(["app/domain/core/Collections"], (collections) => { describe('LinkedList', () => { it('should be able to store strings for lookup', () => { var list = new collections.Collections.LinkedList<string>(); list.add("item1"); expect(list.first()).toBe("item1"); }); }); }); However, collections is of type any so that I can not use it for type