qunit

QUnit Async Tests with setup And teardown

本秂侑毒 提交于 2019-12-01 09:11:54
I need a little help understanding QUnit internas. I read its source from time to time, but i'm still writing weird test when it comes to asynchronous tests. I understand the concept of asynchronous tests, and the stop() and start() methods (and why they are needed), but when i combine them with setup and teardown i get a lot of weired situations. Here is my Testcode: use(['Psc.Exception','Psc.Code'], function () { module("async", { setup: function () { console.log('setup'); }, teardown: function () { console.log('teardown'); } }); asyncTest("test1", function () { expect(0); console.log('test1

Testing a whole page redirect in qUnit

允我心安 提交于 2019-12-01 04:09:33
I have the following function var redirect = function() { window.location.href = "http://www.google.com"; } I want to test this function using qUnit. The problem is, when I call up the HTML document in which my tests run, as soon as it gets to the test that calls redirect() , the browser loads google.com. What I would like to do is mock out window.location.href somehow so that it doesn't redirect, and so I can check that it was set to the proper value. Rewriting this in a manner that it would be more testable would be an acceptable answer and is welcomed. Since I am using qUnit, some jQuery

Testing a whole page redirect in qUnit

一笑奈何 提交于 2019-12-01 02:03:37
问题 I have the following function var redirect = function() { window.location.href = "http://www.google.com"; } I want to test this function using qUnit. The problem is, when I call up the HTML document in which my tests run, as soon as it gets to the test that calls redirect() , the browser loads google.com. What I would like to do is mock out window.location.href somehow so that it doesn't redirect, and so I can check that it was set to the proper value. Rewriting this in a manner that it would

How can I trigger a native Javascript event from a QUnit test?

旧时模样 提交于 2019-11-30 17:35:38
问题 I'm working on a Javascript library that does not depend on jQuery, though I have jQuery and QUnit available in my tests. In the library, I attach an event to an element the way jQuery does: if (document.addEventListener) { tab.addEventListener('click', MyModule.show, false); } else if (document.attachEvent) { tab.attachEvent('click', MyModule.show); } I tried calling $('#tab').click(); in my QUnit test, but it doesn't cause my event handler to be called. 回答1: jQuery has its own event

Jenkins + qUnit

核能气质少年 提交于 2019-11-30 13:36:58
问题 How to easily integrate Jenkins with qUnit? I gonna use real browser (like firefox and chrome) to run tests. My server runs on RedHat 6.1 Linux. I think I have all needed plugins/libraries but I still don't know how to make it working. I'm working with Jenkins 1st time (on server side). //Edit: It would be wonderful if someone can share idea how to build coverage report too. Thanks in advance :). 回答1: Saying Jenkins and QUnit is only part of the puzzle. You still need a web browser and a way

I need a number of different full-page DOM samples for my qUnit test suite

与世无争的帅哥 提交于 2019-11-30 09:19:10
I have a small amount of Javascript to test, but it operates on the entire page, for example, finding elements by numbered ids like "#t34". I need to create a handful of different pages to test the different possible configurations. I see that I can use qunit-fixture to create a DOM tree for the tests to access, but each page configuration needs to be a complete page, since it will find elements by id. The various qUnit tutorials out there seem focused on the simple examples of pure Javascript functions performing simple arithmetic. I need help understanding how to build a real test suite

How do I run a function before each test when using qUnit?

感情迁移 提交于 2019-11-30 09:06:10
What is the equivalent of nUnits [SetUp] attribute for qUnit? Perry Tew Registering a QUnit Callback var mySetupFunc(details){/* setup code */} QUnit.testStart(mySetupFunc); Callback Details As of QUnit version 1.10.0pre-A, each registered callback will receive a hash as the first (and only) parameter. I've named mine 'details' in the example above. The contents of the hash vary by callback. Here's a list of information in each hash. begin (start of all tests) {} /* empty hash */ done (end of all tests) failed: (int) total tests failed passed: (int) total tests passed total: (int) total tests

Qunit + JSCoverage + Jenkins

◇◆丶佛笑我妖孽 提交于 2019-11-30 08:54:33
I have started using Qunit to test my JS code. I am looking into JSCoverage to generate the coverage reports later. We have a CI server (Jenkins) which already do a few things with our PHP code and I was wondering if anyone can comment on how I can integrate the report from my Qunit and JSCoverage into Jenkins Thanks Sparsh malenkiy_scot QUnit: use QUnit API to generate junit XML files. Here's a sample . In Post-build Actions for your job you then check Publish JUnit test result report and specify your junit XML files (or their file pattern). Jenkins will then mark builds that have failed

Jenkins + qUnit

元气小坏坏 提交于 2019-11-30 07:33:23
How to easily integrate Jenkins with qUnit? I gonna use real browser (like firefox and chrome) to run tests. My server runs on RedHat 6.1 Linux. I think I have all needed plugins/libraries but I still don't know how to make it working. I'm working with Jenkins 1st time (on server side). //Edit: It would be wonderful if someone can share idea how to build coverage report too. Thanks in advance :). Saying Jenkins and QUnit is only part of the puzzle. You still need a web browser and a way to get a JUnit style XML file from the QUnit results on to disk. While there is Selenium and Webdriver for

Qunit parameterized tests and mocking

拈花ヽ惹草 提交于 2019-11-29 20:09:47
I have two questions: Can you have parameterised unit tests in qunit? How do you do mocking with qunit e.g. mocking a getJSON call? Thanks For mocking ajax requests, you can try something like this... Here's the function you want to test: var functionToTest = function () { $.ajax({ url: 'someUrl', type: 'POST', dataType: 'json', data: 'foo=1&foo=2&foo=3', success: function (data) { $('#main').html(data.someProp); } }); }; Here's the test case: test('ajax mock test', function () { var options = null; jQuery.ajax = function (param) { options = param; }; functionToTest(); options.success({