qunit

What are some JavaScript Unit Testing and Mocking Frameworks you have used? [closed]

ε祈祈猫儿з 提交于 2019-11-29 19:37:35
My main JavaScript framework is jQuery so I would like my unit test and mocking frameworks to be compatible with that. I'd rather not have to introduce another JavaScript framework. I am currently using QUnit for unit testing and Jack for mocking, but I am pretty new to the whole unit testing of JavaScript. Does anyone else have a better tool to suggest? What has worked for you? QUnit jQUnit Writing JS tests with QUnit and jQUnit QUnit is the unit testing framework for the jQuery JavaScript framework. The testing framework itself uses the jQuery library, but the tests can be written for any

Backbone and Require how to add Qunit

坚强是说给别人听的谎言 提交于 2019-11-29 15:41:43
问题 I'm using Backbone and Require.js. Everything works great but, I would like to add some unit tests to my application. I decided use Qunit.js. In my main.js file I create new object EventsView : require.config({ paths: { jquery: 'libs/jquery', underscore: 'libs/underscore', backbone: 'libs/backbone', qunit: 'test/libs/qunit-1.10.0 } }); require(['view/eventsView', 'test/eventsView_test', 'test/eventView_test' ], function(EventsView){ var events = new EventsView; //here I create first object my

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

若如初见. 提交于 2019-11-29 14:29:37
问题 What is the equivalent of nUnits [SetUp] attribute for qUnit? 回答1: 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

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

自作多情 提交于 2019-11-29 13:56:39
问题 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

Qunit + JSCoverage + Jenkins

偶尔善良 提交于 2019-11-29 12:36:38
问题 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 回答1: 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

How to Unit Test with Qunit a Knockout View Model that uses throttle on observables

不问归期 提交于 2019-11-29 11:29:32
Supposed this is my view model function VM() { var self = this; this.Status = ko.observable(false); this.A = ko.observable(); this.B = ko.computed( function() { return self.A(); } ).extend( throttle: 200 ); this.B.subscribe( function() { self.Status(true); setTimeout( //ajax simulation function(){ self.Status(false); } ,200) } ); } I want a test that verifies status toggles between true and false as A is set but i can't get past the dual async nature of the VM. Is there a way to test this with multiple stop()/start() calls? If you only what to test that the Status toggles between true and

QUnit的使用

不羁岁月 提交于 2019-11-29 08:38:53
最近我准备构建一个自己的轻量级的库,但是我遇到了一些问题,最大的问题就是比如写着写着,我怕后面写的东西会覆盖掉前面的一些功能,所以我只能不停的测试,于是我想到了用一些测试库,试着安装传说中的mocha啥的,on my god,我的破电脑完全不给力装不上去,最后找了这一款超级轻量级的语法简单的测试库,而且还是牛逼的John Resig发明的. ``` QUnit.test( "isFunction", function( assert ) assert.expect( 2 );//指明回调里的断言的次数 function calc( x, operation ) { return operation( x ); } var result = calc( 2, function( x ) { assert.ok( true, "calc() calls operation function" ); return x * x; }); assert.equal( result, 4, "2 square equals 4" ); }); ``` 统计事件执行次数 ``` QUnit.test( "a test", function( assert ) { assert.expect( 1 ); var $body = $( "body" ); $body.on( "click",

sinon.js的使用

半世苍凉 提交于 2019-11-29 08:38:23
<!DOCTYPE html> <html lang="en"> <head> <title>QUnit/Sinon.JS</title> <link rel="stylesheet" href="qunit.css" type="text/css" media="screen"> </head> <body> <h1 id="qunit-header">QUnit/Sinon.JS Test</h1> <h2 id="qunit-banner"></h2> <h2 id="qunit-userAgent"></h2> <ol id="qunit-tests"></ol> <div id="qunit"></div> <div id="qunit-fixture"></div> <script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script type="text/javascript" src="qunit.js"></script> <script type="text/javascript" src="js/sinon-1.17.2.js"></script> <script type="text/javascript" src="js/sinon-qunit-1.0.0.js"><

QUnit, Sinon.js & Backbone unit test frustration: sinon spy appears to fail to detect Backbone Model event callbacks

老子叫甜甜 提交于 2019-11-29 03:50:17
问题 In the following unit test code: TestModel = Backbone.Model.extend({ defaults: { 'selection': null }, initialize: function() { this.on('change:selection', this.doSomething); }, doSomething: function() { console.log("Something has been done."); } }); module("Test", { setup: function() { this.testModel = new TestModel(); } }); test("intra-model event bindings", function() { this.spy(this.testModel, 'doSomething'); ok(!this.testModel.doSomething.called); this.testModel.doSomething(); ok(this

Running JavaScript unit tests headlessly in a Continuous Integration build

試著忘記壹切 提交于 2019-11-28 15:16:11
I have a webapp build plan running on a Continuous Integration system ( Atlassian Bamboo 2.5). I need to incorporate QUnit -based JavaScript unit tests into the build plan so that on each build, the Javascript tests would be run and Bamboo would interpret the test results. Preferably I would like to be able to make the build process "standalone" so that no connections to external servers would be required. Good ideas on how to accomplish this? The CI system running the build process is on an Ubuntu Linux server. As I managed to come up with a solution myself, I thought it would be a good idea