qunit

How to stop Global Failures in qUnit?

◇◆丶佛笑我妖孽 提交于 2019-12-04 02:27:57
I'm new to qunit, and am attempting to integrate it with an existing environment. One of the issues I get on pages that utilize jQuery is this: global failure (1, 0, 1)Rerun6 ms Uncaught ReferenceError: $ is not defined I think this is because I'm not calling the jquery library in the qunit HTML. Is it possible to set a parameter to ignore globals like this? I am trying to make the HTML as flexible as possible, and as many editors have different dependencies, I only want qunit to test the functions I specifically give it to test. I'm stumped at the same error, however without using jQuery. The

Post-mortem unit testing

喜你入骨 提交于 2019-12-04 01:46:10
I do version control with Git, and unit testing with QUnit. Sometimes I find a bug in my software that was not present in a past version. It's easy for me to write a unit test specifically for that bug. Given that unit test, can I easily go trough all my past commits and test the build with that unit test, so that I can pinpoint which commit caused the breakage? Use git bisect for this, please see this page . Since you're testing JavaScript, you will probably have to run the tests by hand and run git bisect good and git bisect bad as appropriate. However, if you can run your unit test from the

Trying to set up Grunt to automate some testing, testing works fine in the browser but not at the command line

ⅰ亾dé卋堺 提交于 2019-12-03 15:34:34
I'm currently trying to incorporate GruntJS with a few plugins (PhantomJS Qunit and Connect plugins). However, setting up a simple test is throwing me errors and I can't find the solution despite a few days of searching. I'm using a local web server (MAMP) and the website is running on a CMS. Running the tests by accessing the test template in a browser works fine, but when trying to access the same tools via the command line using sudo grunt test PhantomJS return an odd error: Running "qunit:all" (qunit) task Testing http://user-guides:80/test/test.html Warning: PhantomJS timed out, possibly

avoid / capture / verify a Javascript alert when testing a method that displays one with qunit

空扰寡人 提交于 2019-12-03 15:19:12
I'm just starting using Qunit and would like to know whether is there a way to capture/verify/omit alerts, For example: function to_test() { alert("I'm displaying an alert"); return 42; } and then have something like: test("to_test", function() { //in this case I'd like to test the alert. alerts("I'm displaying an alert", to_test(), "to_test() should display an alert"); equals(42, to_test(), "to_test() should return 42" ); // in this case I'd like to omit the alert }); I'm open to the suggestion of using another unit testing tool as well. Thanks in advance! memetech Alright, looks like Sinon

Recommended structure for testing Javascript with QUnit in ASP.NET

青春壹個敷衍的年華 提交于 2019-12-03 15:03:54
问题 I have a standard ASP.NET MVC (version 2 preview 2) solution with the actual project and server-side unit tests in separate projects. Because this project is very client-side heavy, I want to make a ClientTest project as well that uses QUnit to test the main project. I've thought of creating a regular ASP.NET webforms project with a single HTML file that would load the various scripts in my Scripts/ directory and test them with QUnit. Unfortunately this will spawn another ASP.NET Development

Take screenshot from Karma while running tests in PhantomJS 2?

不羁岁月 提交于 2019-12-03 14:19:34
I need a way to take a screenshot during a test which uses QUnit and Karma to run inside PhantomJS 2.0.1 I've found this command: window.top.callPhantom('render'); That doesn't throw any error but doesn't seem to work, or at least, I don't know where to look for the taken screenshot. Any clue? Fez Vrasta Found a way! Solution I had to edit my custom PhantomJS custom launcher adding an option: PhantomJSCustom: { base: 'PhantomJS', options: { onCallback: function(data){ if (data.type === "render") { // this function will not have the scope of karma.conf.js so we must define any global variable

QUnit: How to test ajax call without modifying the ajax call

荒凉一梦 提交于 2019-12-03 13:27:58
问题 How can I write a QUnit test for this: function doSomethingWithAjax() { $.ajax({ url: '/GetHelloWorld', success: function(data) { $("#responseFromServer").text(data); }, }); } Mockjax+qunit requires a start() call in the ajax complete() method. 回答1: test("should mock ajax", function() { $.ajax = function(options) { equals(options.url, "/GetHelloWorld"); options.success("Hello"); }; doSomethingWithAjax(); equal($("#responseFromServer").text(), "Hello"); }); 回答2: The jasmine-ajax library allows

Access RequireJS path configuration

谁说我不能喝 提交于 2019-12-03 12:46:37
I notice in the documentation there is a way to pass custom configuration into a module : requirejs.config({ baseUrl: './js', paths: { jquery: 'libs/jquery-1.9.1', jqueryui: 'libs/jquery-ui-1.9.2' }, config: { 'baz': { color: 'blue' } } }); Which you can then access from the module: define(['module'], function (module) { var color = module.config().color; // 'blue' }); But is there also a way to access the top-level paths configuration, something like this? define(['module', 'require'], function (module, require) { console.log( module.paths() ); // no method paths() console.log( require.paths(

How can we execute Unit Tests against DOM manipulation?

谁都会走 提交于 2019-12-03 10:35:06
The introduction to QUnit over at netTuts.com spawns an interesting exchange (never resolved) over how to apply unit tests against actions that manipulate the DOM. The following quote (Alex York) gets to the crux: What would be nice is that if you had a function like this: function add(a, b) { var result = a + b; $(“input#ResultTestBox”).val(result); In the above test, I would love to test two things: the addition of a and b, and the result correctly being put into a DOM element. I would love to test the second thing by providing some mock HTML. Possible? But, like I said...unresolved.

Uncaught Error: Assertion Failed: calling set on destroyed object

孤者浪人 提交于 2019-12-03 10:30:04
问题 working in ember-cli testing. After all tests passed it returns extra two test with errors. Uncaught Error: Assertion Failed: calling set on destroyed object Source : '../dist/assets/vendor.js:13269' this is one unit test configuration import Ember from "ember"; import { test,moduleFor } from 'ember-qunit'; import startApp from '../helpers/start-app'; var App; module('An Integration test',{ setup:function(){ App=startApp(); }, teardown: function() { Ember.run(App, 'destroy'); } }); 回答1: This