├── .gitignore ├── addons ├── themes │ ├── README.md │ ├── nv.html │ ├── gabe.html │ ├── nv.css │ └── gabe.css ├── composite │ ├── qunit-composite.css │ ├── README.md │ ├── composite-demo-test.html │ ├── index.html │ └── qunit-composite.js ├── canvas │ ├── qunit-canvas.js │ ├── README.md │ ├── canvas.html │ └── canvas-test.js ├── step │ ├── step-test.js │ ├── step.html │ ├── README.md │ └── qunit-step.js ├── phantomjs │ ├── README.md │ └── runner.js ├── close-enough │ ├── close-enough.html │ ├── README.md │ ├── close-enough-test.js │ └── qunit-close-enough.js └── junitlogger │ ├── index.html │ └── junitlogger.js ├── test ├── swarminject.js ├── logs.html ├── index.html ├── node-test.js ├── narwhal-test.js ├── headless.html ├── logs.js ├── test.js └── deepEqual.js ├── package.json ├── AUTHORS.txt ├── README.md ├── grunt.js ├── qunit └── qunit.css └── History.md /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | *~ 3 | *.diff 4 | *.patch 5 | .DS_Store 6 | .settings 7 | node_modules 8 | dist/ 9 | -------------------------------------------------------------------------------- /addons/themes/README.md: -------------------------------------------------------------------------------- 1 | Themes 2 | ====== 3 | 4 | These custom themes fully replace the default qunit.css file and should work 5 | with the default markup. To see them in action, open the html file for each. 6 | They'll run the QUnit testsuite itself. -------------------------------------------------------------------------------- /addons/composite/qunit-composite.css: -------------------------------------------------------------------------------- 1 | iframe.qunit-subsuite{ 2 | position: fixed; 3 | bottom: 0; 4 | left: 0; 5 | 6 | margin: 0; 7 | padding: 0; 8 | border-width: 1px 0 0; 9 | height: 45%; 10 | width: 100%; 11 | 12 | background: #fff; 13 | } -------------------------------------------------------------------------------- /addons/canvas/qunit-canvas.js: -------------------------------------------------------------------------------- 1 | QUnit.extend( QUnit, { 2 | pixelEqual: function(canvas, x, y, r, g, b, a, message) { 3 | var actual = Array.prototype.slice.apply(canvas.getContext('2d').getImageData(x, y, 1, 1).data), expected = [r, g, b, a]; 4 | QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); 5 | } 6 | }); 7 | -------------------------------------------------------------------------------- /addons/step/step-test.js: -------------------------------------------------------------------------------- 1 | module('Step Addon'); 2 | test("step", 3, function () { 3 | QUnit.step(1, "step starts at 1"); 4 | setTimeout(function () { 5 | start(); 6 | QUnit.step(3); 7 | }, 100); 8 | QUnit.step(2, "before the setTimeout callback is run"); 9 | stop(); 10 | }); 11 | test("step counter", 1, function () { 12 | QUnit.step(1, "each test has its own step counter"); 13 | }); -------------------------------------------------------------------------------- /test/swarminject.js: -------------------------------------------------------------------------------- 1 | // load testswarm agent 2 | (function() { 3 | var url = window.location.search; 4 | url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); 5 | if ( !url || url.indexOf("http") !== 0 ) { 6 | return; 7 | } 8 | document.write(""); 9 | })(); 10 | -------------------------------------------------------------------------------- /addons/phantomjs/README.md: -------------------------------------------------------------------------------- 1 | PhantomJS Runner 2 | ================ 3 | 4 | A runner for PhantomJS, providing console output for tests. 5 | 6 | Usage: 7 | 8 | phantomjs runner.js url 9 | 10 | Example: 11 | 12 | phantomjs runner.js http://localhost/qunit/test 13 | 14 | If you're using Grunt, you should take a look at its [qunit task](https://github.com/cowboy/grunt/blob/master/docs/task_qunit.md). -------------------------------------------------------------------------------- /test/logs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 |
11 |
test markup
12 | 13 | 14 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QUnit Test Suite 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
test markup
15 | 16 | 17 | -------------------------------------------------------------------------------- /addons/step/step.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QUnit Test Suite - Step Addon 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /addons/themes/nv.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite - NV Theme 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
test markup
13 | 14 | 15 | -------------------------------------------------------------------------------- /addons/themes/gabe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite - Gabe Theme 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
test markup
13 | 14 | 15 | -------------------------------------------------------------------------------- /addons/close-enough/close-enough.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QUnit Test Suite - Close Enough Addon 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /addons/step/README.md: -------------------------------------------------------------------------------- 1 | QUnit.step() - A QUnit Addon For Testing execution in order 2 | ============================================================ 3 | 4 | This addon for QUnit adds a step method that allows you to assert 5 | the proper sequence in which the code should execute. 6 | 7 | Example: 8 | 9 | test("example test", function () { 10 | function x() { 11 | QUnit.step(2, "function y should be called first"); 12 | } 13 | function y() { 14 | QUnit.step(1); 15 | } 16 | y(); 17 | x(); 18 | }); -------------------------------------------------------------------------------- /addons/composite/README.md: -------------------------------------------------------------------------------- 1 | Composite - A QUnit Addon For Running Multiple Test Files 2 | ================================ 3 | 4 | Composite is a QUnit addon that, when handed an array of files, will 5 | open each of those files inside of an iframe, run the tests and 6 | display the results as a single suite of QUnit tests. 7 | 8 | The Rerun link next to each suite allows you to quickly rerun that suite, 9 | outside the composite runner. 10 | 11 | If you want to see what assertion failed in a long list of assertions, 12 | just use the regular "Hide passed tests" checkbox. -------------------------------------------------------------------------------- /addons/canvas/README.md: -------------------------------------------------------------------------------- 1 | Canvas - A QUnit Addon For Testing Canvas Rendering 2 | ================================ 3 | 4 | This addon for QUnit adds a pixelEqual method that allows you to assert 5 | individual pixel values in a given canvas. 6 | 7 | Usage: 8 | 9 | pixelEqual(canvas, x, y, r, g, b, a, message) 10 | 11 | Where: 12 | 13 | * canvas: Reference to a canvas element 14 | * x, y: Coordinates of the pixel to test 15 | * r, g, b, a: The color and opacity value of the pixel that you except 16 | * message: Optional message, same as for other assertions 17 | -------------------------------------------------------------------------------- /addons/canvas/canvas.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QUnit Test Suite - Canvas Addon 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/node-test.js: -------------------------------------------------------------------------------- 1 | // run with 2 | // node test/node-test.js 3 | var QUnit = require("../qunit/qunit"); 4 | QUnit.log(function(details) { 5 | if (!details.result) { 6 | var output = "FAILED: " + (details.message ? details.message + ", " : ""); 7 | if (details.actual) { 8 | output += "expected: " + details.expected + ", actual: " + details.actual; 9 | } 10 | if (details.source) { 11 | output += ", " + details.source; 12 | } 13 | console.log(output); 14 | } 15 | }); 16 | QUnit.test("yo", function() { 17 | QUnit.equal(true, false); 18 | QUnit.equal(true, false, "gotta fail"); 19 | x.y.z; 20 | }); -------------------------------------------------------------------------------- /test/narwhal-test.js: -------------------------------------------------------------------------------- 1 | // run with 2 | // node test/node-test.js 3 | var QUnit = require("../qunit/qunit"); 4 | QUnit.log(function(details) { 5 | if (!details.result) { 6 | var output = "FAILED: " + (details.message ? details.message + ", " : ""); 7 | if (details.actual) { 8 | output += "expected: " + details.expected + ", actual: " + details.actual; 9 | } 10 | if (details.source) { 11 | output += ", " + details.source; 12 | } 13 | print(output); 14 | } else { 15 | print("ok!"); 16 | } 17 | }); 18 | QUnit.test("yo", function() { 19 | QUnit.equal(true, false); 20 | QUnit.equal(true, false, "gotta fail"); 21 | x.y.z; 22 | }); -------------------------------------------------------------------------------- /addons/close-enough/README.md: -------------------------------------------------------------------------------- 1 | Close-Enough - A QUnit Addon For Number Approximations 2 | ================================ 3 | 4 | This addon for QUnit adds close and notClose assertion methods, to test that 5 | numbers are close enough (or different enough) from an expected number, with 6 | a specified accuracy. 7 | 8 | Usage: 9 | 10 | close(actual, expected, maxDifference, message) 11 | notClose(actual, expected, minDifference, message) 12 | 13 | Where: 14 | 15 | * maxDifference: the maximum inclusive difference allowed between the actual and expected numbers 16 | * minDifference: the minimum exclusive difference allowed between the actual and expected numbers 17 | * actual, expected, message: The usual 18 | -------------------------------------------------------------------------------- /addons/composite/composite-demo-test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QUnit SubsuiteRunner Test Suite 6 | 7 | 8 | 9 | 10 | 11 | 12 | 20 | 21 | 22 |
23 |
24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /addons/step/qunit-step.js: -------------------------------------------------------------------------------- 1 | QUnit.extend( QUnit, { 2 | 3 | /** 4 | * Check the sequence/order 5 | * 6 | * @example step(1); setTimeout(function () { step(3); }, 100); step(2); 7 | * @param Number expected The excepted step within the test() 8 | * @param String message (optional) 9 | */ 10 | step: function (expected, message) { 11 | this.config.current.step++; // increment internal step counter. 12 | if (typeof message === "undefined") { 13 | message = "step " + expected; 14 | } 15 | var actual = this.config.current.step; 16 | QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); 17 | } 18 | }); 19 | 20 | /** 21 | * Reset the step counter for every test() 22 | */ 23 | QUnit.testStart(function () { 24 | this.config.current.step = 0; 25 | }); 26 | -------------------------------------------------------------------------------- /test/headless.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 20 | 21 | 22 |
test markup
23 | 24 | 25 | -------------------------------------------------------------------------------- /addons/close-enough/close-enough-test.js: -------------------------------------------------------------------------------- 1 | test("Close Numbers", function () { 2 | var halfPi = Math.PI / 2, 3 | sqrt2 = Math.sqrt(2); 4 | 5 | QUnit.close(7, 7, 0); 6 | QUnit.close(7, 7.1, 0.1); 7 | QUnit.close(7, 7.1, 0.2); 8 | 9 | QUnit.close(3.141, Math.PI, 0.001); 10 | QUnit.close(3.1, Math.PI, 0.1); 11 | 12 | QUnit.close(halfPi, 1.57, 0.001); 13 | 14 | QUnit.close(sqrt2, 1.4142, 0.0001); 15 | 16 | QUnit.close(Infinity, Infinity, 1); 17 | }); 18 | 19 | test("Distant Numbers", function () { 20 | var halfPi = Math.PI / 2, 21 | sqrt2 = Math.sqrt(2); 22 | 23 | QUnit.notClose(6, 7, 0); 24 | QUnit.notClose(7, 7.2, 0.1); 25 | QUnit.notClose(7, 7.2, 0.19999999999); 26 | 27 | QUnit.notClose(3.141, Math.PI, 0.0001); 28 | QUnit.notClose(3.1, Math.PI, 0.001); 29 | 30 | QUnit.notClose(halfPi, 1.57, 0.0001); 31 | 32 | QUnit.notClose(sqrt2, 1.4142, 0.00001); 33 | 34 | QUnit.notClose(Infinity, -Infinity, 5); 35 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "qunitjs", 3 | "title": "QUnit", 4 | "description": "An easy-to-use JavaScript Unit Testing framework.", 5 | "version": "1.10.0", 6 | "author": { 7 | "name": "jQuery Foundation and other contributors", 8 | "url": "https://github.com/jquery/qunit/blob/master/AUTHORS.txt" 9 | }, 10 | "contributors": [ 11 | "John Resig (http://ejohn.org/)", 12 | "Jörn Zaefferer (http://bassistance.de/)" 13 | ], 14 | "homepage": "http://qunitjs.com", 15 | "repository": { 16 | "type": "git", 17 | "url": "git://github.com/jquery/qunit.git" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/jquery/qunit/issues" 21 | }, 22 | "license": { 23 | "name": "MIT", 24 | "url": "http://www.opensource.org/licenses/mit-license.php" 25 | }, 26 | "keywords": [ 27 | "testing", 28 | "unit", 29 | "jquery" 30 | ], 31 | "main": "qunit/qunit.js", 32 | "devDependencies": { 33 | "grunt": "0.3.x", 34 | "grunt-git-authors": "1.0.0", 35 | "testswarm": "0.2.2" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /addons/junitlogger/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QUnit Test Suite - JUnit report 6 | 7 | 8 | 9 | 40 | 41 | 42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /addons/composite/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Composite 6 | 7 | 8 |

Composite

9 |

A QUnit Addon For Running Multiple Test Files

10 |

Composite is a QUnit addon that, when handed an array of 11 | files, will open each of those files inside of an iframe, run 12 | the tests and display the results as a single suite of QUnit 13 | tests.

14 |

Using Composite

15 |

To use Composite, setup a standard QUnit html page as you 16 | would with other QUnit tests. Remember to include composite.js 17 | and composite.css. Then, inside of either an external js file, 18 | or a script block call the only new method that Composite 19 | exposes, QUnit.testSuites().

QUnit.testSuites() is 20 | passed an array of test files to run as follows:

21 |
22 | QUnit.testSuites([
23 |     "test-file-1.html",
24 |     "test-file-2.html",
25 |     "test-file-3.html"
26 | ]);
27 | 		
28 |

Tests

29 |

30 | Composite Demo: A suite which demoes how Composite is bootstrapped and run. 31 |

32 | 33 | 34 | -------------------------------------------------------------------------------- /addons/close-enough/qunit-close-enough.js: -------------------------------------------------------------------------------- 1 | QUnit.extend( QUnit, { 2 | /** 3 | * Checks that the first two arguments are equal, or are numbers close enough to be considered equal 4 | * based on a specified maximum allowable difference. 5 | * 6 | * @example close(3.141, Math.PI, 0.001); 7 | * 8 | * @param Number actual 9 | * @param Number expected 10 | * @param Number maxDifference (the maximum inclusive difference allowed between the actual and expected numbers) 11 | * @param String message (optional) 12 | */ 13 | close: function(actual, expected, maxDifference, message) { 14 | var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference; 15 | QUnit.push(passes, actual, expected, message); 16 | }, 17 | 18 | /** 19 | * Checks that the first two arguments are numbers with differences greater than the specified 20 | * minimum difference. 21 | * 22 | * @example notClose(3.1, Math.PI, 0.001); 23 | * 24 | * @param Number actual 25 | * @param Number expected 26 | * @param Number minDifference (the minimum exclusive difference allowed between the actual and expected numbers) 27 | * @param String message (optional) 28 | */ 29 | notClose: function(actual, expected, minDifference, message) { 30 | QUnit.push(Math.abs(actual - expected) > minDifference, actual, expected, message); 31 | } 32 | }); -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Jörn Zaefferer 2 | Ariel Flesler 3 | Scott González 4 | Richard Worth 5 | Philippe Rathé 6 | John Resig 7 | Will Moffat 8 | Jan Kassens 9 | Ziling Zhao 10 | Ryan Szulczewski 11 | Chris Lloyd 12 | Louis-Rémi Babé 13 | Jake Archibald 14 | Frances Berriman 15 | Rune Halvorsen 16 | Chris Thatcher 17 | Fábio Rehm 18 | Leon Sorokin 19 | Douglas Neiner 20 | Paul Elliott 21 | Nikita Vasilyev 22 | Benjamin Lee 23 | Paul Irish 24 | Oleg Slobodskoi 25 | Anton Matzneller 26 | Aurélien Bombo 27 | Mathias Bynens 28 | Erik Vold 29 | Wesley Walser 30 | Rob Kinninmont 31 | Marc Portier 32 | Michael Righi 33 | Timo Tijhof 34 | Jan Alonzo 35 | Daniel Trebbien 36 | Bob Fanger 37 | Markus Messner-Chaney 38 | Trevor Parscal 39 | Ashar Voultoiz 40 | Jimmy Mabey 41 | Domenic Denicola 42 | Mike Sherov 43 | Seong-A Kong 44 | Graham Conzett 45 | Niall Smart 46 | Johan Sörlin 47 | Gijs Kruitbosch 48 | Erkan Yilmaz 49 | Jonathan Sanchez 50 | Keith Cirkel 51 | Rick Waldron 52 | Herbert Vojčík 53 | Richard Gibson 54 | Alex J Burke 55 | Sergii Kliuchnyk 56 | -------------------------------------------------------------------------------- /addons/phantomjs/runner.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Qt+WebKit powered headless test runner using Phantomjs 3 | * 4 | * Phantomjs installation: http://code.google.com/p/phantomjs/wiki/BuildInstructions 5 | * 6 | * Run with: 7 | * phantomjs runner.js [url-of-your-qunit-testsuite] 8 | * 9 | * E.g. 10 | * phantomjs runner.js http://localhost/qunit/test 11 | */ 12 | 13 | var url = phantom.args[0]; 14 | 15 | var page = require('webpage').create(); 16 | 17 | // Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this") 18 | page.onConsoleMessage = function(msg) { 19 | console.log(msg); 20 | }; 21 | 22 | page.onInitialized = function() { 23 | page.evaluate(addLogging); 24 | }; 25 | page.open(url, function(status){ 26 | if (status !== "success") { 27 | console.log("Unable to access network: " + status); 28 | phantom.exit(1); 29 | } else { 30 | // page.evaluate(addLogging); 31 | var interval = setInterval(function() { 32 | if (finished()) { 33 | clearInterval(interval); 34 | onfinishedTests(); 35 | } 36 | }, 500); 37 | } 38 | }); 39 | 40 | function finished() { 41 | return page.evaluate(function(){ 42 | return !!window.qunitDone; 43 | }); 44 | } 45 | 46 | function onfinishedTests() { 47 | var output = page.evaluate(function() { 48 | return JSON.stringify(window.qunitDone); 49 | }); 50 | phantom.exit(JSON.parse(output).failed > 0 ? 1 : 0); 51 | } 52 | 53 | function addLogging() { 54 | window.document.addEventListener( "DOMContentLoaded", function() { 55 | var current_test_assertions = []; 56 | 57 | QUnit.testDone(function(result) { 58 | var name = result.module + ': ' + result.name; 59 | var i; 60 | 61 | if (result.failed) { 62 | console.log('Assertion Failed: ' + name); 63 | 64 | for (i = 0; i < current_test_assertions.length; i++) { 65 | console.log(' ' + current_test_assertions[i]); 66 | } 67 | } 68 | 69 | current_test_assertions = []; 70 | }); 71 | 72 | QUnit.log(function(details) { 73 | var response; 74 | 75 | if (details.result) { 76 | return; 77 | } 78 | 79 | response = details.message || ''; 80 | 81 | if (typeof details.expected !== 'undefined') { 82 | if (response) { 83 | response += ', '; 84 | } 85 | 86 | response += 'expected: ' + details.expected + ', but was: ' + details.actual; 87 | } 88 | 89 | current_test_assertions.push('Failed assertion: ' + response); 90 | }); 91 | 92 | QUnit.done(function(result){ 93 | console.log('Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.'); 94 | window.qunitDone = result; 95 | }); 96 | }, false ); 97 | } 98 | -------------------------------------------------------------------------------- /addons/canvas/canvas-test.js: -------------------------------------------------------------------------------- 1 | test("Canvas pixels", function () { 2 | var canvas = document.getElementById('qunit-canvas'), context; 3 | try { 4 | context = canvas.getContext('2d'); 5 | } catch(e) { 6 | // propably no canvas support, just exit 7 | return; 8 | } 9 | context.fillStyle = 'rgba(0, 0, 0, 0)'; 10 | context.fillRect(0, 0, 5, 5); 11 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); 12 | context.clearRect(0,0,5,5); 13 | context.fillStyle = 'rgba(255, 0, 0, 0)'; 14 | context.fillRect(0, 0, 5, 5); 15 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); 16 | context.clearRect(0,0,5,5); 17 | context.fillStyle = 'rgba(0, 255, 0, 0)'; 18 | context.fillRect(0, 0, 5, 5); 19 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); 20 | context.clearRect(0,0,5,5); 21 | context.fillStyle = 'rgba(0, 0, 255, 0)'; 22 | context.fillRect(0, 0, 5, 5); 23 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); 24 | context.clearRect(0,0,5,5); 25 | 26 | context.fillStyle = 'rgba(0, 0, 0, 0.5)'; 27 | context.fillRect(0, 0, 5, 5); 28 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 127); 29 | context.clearRect(0,0,5,5); 30 | context.fillStyle = 'rgba(255, 0, 0, 0.5)'; 31 | context.fillRect(0, 0, 5, 5); 32 | QUnit.pixelEqual(canvas, 0, 0, 255, 0, 0, 127); 33 | context.clearRect(0,0,5,5); 34 | context.fillStyle = 'rgba(0, 255, 0, 0.5)'; 35 | context.fillRect(0, 0, 5, 5); 36 | QUnit.pixelEqual(canvas, 0, 0, 0, 255, 0, 127); 37 | context.clearRect(0,0,5,5); 38 | context.fillStyle = 'rgba(0, 0, 255, 0.5)'; 39 | context.fillRect(0, 0, 5, 5); 40 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 255, 127); 41 | context.clearRect(0,0,5,5); 42 | 43 | context.fillStyle = 'rgba(0, 0, 0, 0.5)'; 44 | context.fillRect(0, 0, 5, 5); 45 | QUnit.pixelEqual(canvas, 2, 2, 0, 0, 0, 127); 46 | context.clearRect(0,0,5,5); 47 | context.fillStyle = 'rgba(255, 0, 0, 0.5)'; 48 | context.fillRect(0, 0, 5, 5); 49 | QUnit.pixelEqual(canvas, 2, 2, 255, 0, 0, 127); 50 | context.clearRect(0,0,5,5); 51 | context.fillStyle = 'rgba(0, 255, 0, 0.5)'; 52 | context.fillRect(0, 0, 5, 5); 53 | QUnit.pixelEqual(canvas, 2, 2, 0, 255, 0, 127); 54 | context.clearRect(0,0,5,5); 55 | context.fillStyle = 'rgba(0, 0, 255, 0.5)'; 56 | context.fillRect(0, 0, 5, 5); 57 | QUnit.pixelEqual(canvas, 2, 2, 0, 0, 255, 127); 58 | context.clearRect(0,0,5,5); 59 | 60 | context.fillStyle = 'rgba(0, 0, 0, 1)'; 61 | context.fillRect(0, 0, 5, 5); 62 | QUnit.pixelEqual(canvas, 4, 4, 0, 0, 0, 255); 63 | context.clearRect(0,0,5,5); 64 | context.fillStyle = 'rgba(255, 0, 0, 1)'; 65 | context.fillRect(0, 0, 5, 5); 66 | QUnit.pixelEqual(canvas, 4, 4, 255, 0, 0, 255); 67 | context.clearRect(0,0,5,5); 68 | context.fillStyle = 'rgba(0, 255, 0, 1)'; 69 | context.fillRect(0, 0, 5, 5); 70 | QUnit.pixelEqual(canvas, 4, 4, 0, 255, 0, 255); 71 | context.clearRect(0,0,5,5); 72 | context.fillStyle = 'rgba(0, 0, 255, 1)'; 73 | context.fillRect(0, 0, 5, 5); 74 | QUnit.pixelEqual(canvas, 4, 4, 0, 0, 255, 255); 75 | context.clearRect(0,0,5,5); 76 | }); 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [QUnit](http://qunitjs.com) - A JavaScript Unit Testing framework. 2 | ================================ 3 | 4 | QUnit is a powerful, easy-to-use, JavaScript test suite. It's used by the jQuery 5 | project to test its code and plugins but is capable of testing any generic 6 | JavaScript code (and even capable of testing JavaScript code on the server-side). 7 | 8 | QUnit is especially useful for regression testing: Whenever a bug is reported, 9 | write a test that asserts the existence of that particular bug. Then fix it and 10 | commit both. Every time you work on the code again, run the tests. If the bug 11 | comes up again - a regression - you'll spot it immediately and know how to fix 12 | it, because you know what code you just changed. 13 | 14 | Having good unit test coverage makes safe refactoring easy and cheap. You can 15 | run the tests after each small refactoring step and always know what change 16 | broke something. 17 | 18 | QUnit is similar to other unit testing frameworks like JUnit, but makes use of 19 | the features JavaScript provides and helps with testing code in the browser, e.g. 20 | with its stop/start facilities for testing asynchronous code. 21 | 22 | If you are interested in helping developing QUnit, you are in the right place. 23 | For related discussions, visit the 24 | [QUnit and Testing forum](http://forum.jquery.com/qunit-and-testing). 25 | 26 | Planning for a qunitjs.com site and other testing tools related work now happens 27 | on the [jQuery Testing Team planning wiki](http://jquerytesting.pbworks.com/w/page/41556026/FrontPage). 28 | 29 | Development 30 | ----------- 31 | 32 | To submit patches, fork the repository, create a branch for the change. Then implement 33 | the change, run `grunt` to lint and test it, then commit, push and create a pull request. 34 | 35 | Include some background for the change in the commit message and `Fixes #nnn`, referring 36 | to the issue number you're addressing. 37 | 38 | To run `grunt`, you need `node` and `npm`, then `npm install grunt -g`. That gives you a global 39 | grunt binary. For additional grunt tasks, also run `npm install`. 40 | 41 | Releases 42 | -------- 43 | 44 | Install git-extras and run `git changelog` to update History.md. 45 | Update qunit/qunit.js|css and package.json to the release version, commit and 46 | tag, update them again to the next version, commit and push commits and tags 47 | (`git push --tags origin master`). 48 | 49 | Put the 'v' in front of the tag, e.g. `v1.8.0`. Clean up the changelog, removing merge commits 50 | or whitespace cleanups. 51 | 52 | To upload to code.jquery.com (replace $version accordingly): 53 | 54 | scp -q qunit/qunit.js jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/qunit/qunit-$version.js 55 | scp -q qunit/qunit.css jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/qunit/qunit-$version.css 56 | 57 | Then update /var/www/html/code.jquery.com/index.html and purge it with: 58 | 59 | curl -s http://code.origin.jquery.com/?reload -------------------------------------------------------------------------------- /addons/composite/qunit-composite.js: -------------------------------------------------------------------------------- 1 | (function( QUnit ) { 2 | 3 | QUnit.extend( QUnit, { 4 | testSuites: function( suites ) { 5 | QUnit.begin(function() { 6 | QUnit.initIframe(); 7 | }); 8 | 9 | for ( var i = 0; i < suites.length; i++ ) { 10 | QUnit.runSuite( suites[i] ); 11 | } 12 | 13 | QUnit.done(function() { 14 | this.iframe.style.display = "none"; 15 | }); 16 | }, 17 | 18 | runSuite: function( suite ) { 19 | asyncTest( suite, function() { 20 | QUnit.iframe.setAttribute( "src", suite ); 21 | }); 22 | }, 23 | 24 | initIframe: function() { 25 | var body = document.body, 26 | iframe = this.iframe = document.createElement( "iframe" ), 27 | iframeWin; 28 | 29 | iframe.className = "qunit-subsuite"; 30 | body.appendChild( iframe ); 31 | 32 | function onIframeLoad() { 33 | var module, test, 34 | count = 0; 35 | 36 | 37 | iframeWin.QUnit.moduleStart(function( data ) { 38 | // capture module name for messages 39 | module = data.name; 40 | }); 41 | 42 | iframeWin.QUnit.testStart(function( data ) { 43 | // capture test name for messages 44 | test = data.name; 45 | }); 46 | iframeWin.QUnit.testDone(function() { 47 | test = null; 48 | }); 49 | 50 | iframeWin.QUnit.log(function( data ) { 51 | if (test === null) { 52 | return; 53 | } 54 | // pass all test details through to the main page 55 | var message = module + ": " + test + ": " + data.message; 56 | expect( ++count ); 57 | QUnit.push( data.result, data.actual, data.expected, message ); 58 | }); 59 | 60 | iframeWin.QUnit.done(function() { 61 | // start the wrapper test from the main page 62 | start(); 63 | }); 64 | } 65 | QUnit.addEvent( iframe, "load", onIframeLoad ); 66 | 67 | iframeWin = iframe.contentWindow; 68 | } 69 | }); 70 | 71 | QUnit.testStart(function( data ) { 72 | // update the test status to show which test suite is running 73 | QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...
 "; 74 | }); 75 | 76 | QUnit.testDone(function() { 77 | var i, 78 | current = QUnit.id( this.config.current.id ), 79 | children = current.children, 80 | src = this.iframe.src; 81 | 82 | // undo the auto-expansion of failed tests 83 | for ( i = 0; i < children.length; i++ ) { 84 | if ( children[i].nodeName === "OL" ) { 85 | children[i].style.display = "none"; 86 | } 87 | } 88 | 89 | QUnit.addEvent(current, "dblclick", function( e ) { 90 | var target = e && e.target ? e.target : window.event.srcElement; 91 | if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) { 92 | target = target.parentNode; 93 | } 94 | if ( window.location && target.nodeName.toLowerCase() === "strong" ) { 95 | window.location = src; 96 | } 97 | }); 98 | 99 | current.getElementsByTagName('a')[0].href = src; 100 | }); 101 | 102 | }( QUnit ) ); 103 | -------------------------------------------------------------------------------- /grunt.js: -------------------------------------------------------------------------------- 1 | /*global config:true, task:true*/ 2 | module.exports = function( grunt ) { 3 | 4 | grunt.loadNpmTasks( "grunt-git-authors" ); 5 | 6 | grunt.initConfig({ 7 | pkg: '', 8 | qunit: { 9 | // TODO include 'test/logs.html' as well 10 | qunit: 'test/index.html', 11 | addons: [ 12 | 'addons/canvas/canvas.html', 13 | 'addons/close-enough/close-enough.html', 14 | 'addons/composite/composite-demo-test.html' 15 | ] 16 | }, 17 | lint: { 18 | qunit: 'qunit/qunit.js', 19 | // addons: 'addons/**/*.js', 20 | grunt: 'grunt.js' 21 | // TODO need to figure out which warnings to fix and which to disable 22 | // tests: 'test/test.js' 23 | }, 24 | jshint: { 25 | qunit: { 26 | options: { 27 | onevar: true, 28 | browser: true, 29 | bitwise: true, 30 | curly: true, 31 | trailing: true, 32 | immed: true, 33 | latedef: false, 34 | newcap: true, 35 | noarg: false, 36 | noempty: true, 37 | nonew: true, 38 | sub: true, 39 | undef: true, 40 | eqnull: true, 41 | proto: true, 42 | smarttabs: true 43 | }, 44 | globals: { 45 | jQuery: true, 46 | exports: true 47 | } 48 | }, 49 | addons: { 50 | options: { 51 | browser: true, 52 | curly: true, 53 | eqnull: true, 54 | eqeqeq: true, 55 | expr: true, 56 | evil: true, 57 | jquery: true, 58 | latedef: true, 59 | noarg: true, 60 | onevar: true, 61 | smarttabs: true, 62 | trailing: true, 63 | undef: true 64 | }, 65 | globals: { 66 | module: true, 67 | test: true, 68 | asyncTest: true, 69 | expect: true, 70 | start: true, 71 | stop: true, 72 | QUnit: true 73 | } 74 | }, 75 | tests: { 76 | } 77 | } 78 | }); 79 | 80 | grunt.registerTask( "build-git", function( sha ) { 81 | function processor( content ) { 82 | var tagline = " - A JavaScript Unit Testing Framework"; 83 | return content.replace( tagline, "-" + sha + " " + grunt.template.today('isoDate') + tagline ); 84 | } 85 | grunt.file.copy( "qunit/qunit.css", "dist/qunit-git.css", { 86 | process: processor 87 | }); 88 | grunt.file.copy( "qunit/qunit.js", "dist/qunit-git.js", { 89 | process: processor 90 | }); 91 | }); 92 | 93 | grunt.registerTask( "testswarm", function( commit, configFile ) { 94 | var testswarm = require( "testswarm" ), 95 | config = grunt.file.readJSON( configFile ).qunit; 96 | testswarm({ 97 | url: config.swarmUrl, 98 | pollInterval: 10000, 99 | timeout: 1000 * 60 * 30, 100 | done: this.async() 101 | }, { 102 | authUsername: "qunit", 103 | authToken: config.authToken, 104 | jobName: 'QUnit commit #' + commit.substr( 0, 10 ) + '', 105 | runMax: config.runMax, 106 | "runNames[]": "QUnit", 107 | "runUrls[]": config.testUrl + commit + "/test/index.html", 108 | "browserSets[]": ["popular"] 109 | }); 110 | }); 111 | 112 | grunt.registerTask('default', 'lint qunit'); 113 | 114 | }; 115 | -------------------------------------------------------------------------------- /test/logs.js: -------------------------------------------------------------------------------- 1 | // TODO disable reordering for this suite! 2 | 3 | 4 | var begin = 0, 5 | moduleStart = 0, 6 | moduleDone = 0, 7 | testStart = 0, 8 | testDone = 0, 9 | log = 0, 10 | moduleContext, 11 | moduleDoneContext, 12 | testContext, 13 | testDoneContext, 14 | logContext; 15 | 16 | QUnit.begin(function() { 17 | begin++; 18 | }); 19 | QUnit.done(function() { 20 | }); 21 | QUnit.moduleStart(function(context) { 22 | moduleStart++; 23 | moduleContext = context; 24 | }); 25 | QUnit.moduleDone(function(context) { 26 | moduleDone++; 27 | moduleDoneContext = context; 28 | }); 29 | QUnit.testStart(function(context) { 30 | testStart++; 31 | testContext = context; 32 | }); 33 | QUnit.testDone(function(context) { 34 | testDone++; 35 | testDoneContext = context; 36 | }); 37 | QUnit.log(function(context) { 38 | log++; 39 | logContext = context; 40 | }); 41 | 42 | var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"]; 43 | for (var i = 0; i < logs.length; i++) { 44 | (function() { 45 | var log = logs[i]; 46 | QUnit[log](function() { 47 | console.log(log, arguments); 48 | }); 49 | })(); 50 | } 51 | 52 | module("logs1"); 53 | 54 | test("test1", 15, function() { 55 | equal(begin, 1); 56 | equal(moduleStart, 1); 57 | equal(testStart, 1); 58 | equal(testDone, 0); 59 | equal(moduleDone, 0); 60 | 61 | deepEqual(logContext, { 62 | name: "test1", 63 | module: "logs1", 64 | result: true, 65 | message: undefined, 66 | actual: 0, 67 | expected: 0 68 | }); 69 | equal("foo", "foo", "msg"); 70 | deepEqual(logContext, { 71 | name: "test1", 72 | module: "logs1", 73 | result: true, 74 | message: "msg", 75 | actual: "foo", 76 | expected: "foo" 77 | }); 78 | strictEqual(testDoneContext, undefined); 79 | deepEqual(testContext, { 80 | module: "logs1", 81 | name: "test1" 82 | }); 83 | strictEqual(moduleDoneContext, undefined); 84 | deepEqual(moduleContext, { 85 | name: "logs1" 86 | }); 87 | ok(true, "msg"); 88 | deepEqual(logContext, { 89 | module: "logs1", 90 | name: "test1", 91 | result: true, 92 | message: "msg" 93 | }); 94 | 95 | equal(log, 14); 96 | }); 97 | test("test2", 10, function() { 98 | equal(begin, 1); 99 | equal(moduleStart, 1); 100 | equal(testStart, 2); 101 | equal(testDone, 1); 102 | equal(moduleDone, 0); 103 | 104 | deepEqual(testDoneContext, { 105 | module: "logs1", 106 | name: "test1", 107 | failed: 0, 108 | passed: 15, 109 | total: 15 110 | }); 111 | deepEqual(testContext, { 112 | module: "logs1", 113 | name: "test2" 114 | }); 115 | strictEqual(moduleDoneContext, undefined); 116 | deepEqual(moduleContext, { 117 | name: "logs1" 118 | }); 119 | 120 | equal(log, 24); 121 | }); 122 | 123 | module("logs2"); 124 | 125 | test("test1", 9, function() { 126 | equal(begin, 1); 127 | equal(moduleStart, 2); 128 | equal(testStart, 3); 129 | equal(testDone, 2); 130 | equal(moduleDone, 1); 131 | 132 | deepEqual(testContext, { 133 | module: "logs2", 134 | name: "test1" 135 | }); 136 | deepEqual(moduleDoneContext, { 137 | name: "logs1", 138 | failed: 0, 139 | passed: 25, 140 | total: 25 141 | }); 142 | deepEqual(moduleContext, { 143 | name: "logs2" 144 | }); 145 | 146 | equal(log, 33); 147 | }); 148 | test("test2", 8, function() { 149 | equal(begin, 1); 150 | equal(moduleStart, 2); 151 | equal(testStart, 4); 152 | equal(testDone, 3); 153 | equal(moduleDone, 1); 154 | 155 | deepEqual(testContext, { 156 | module: "logs2", 157 | name: "test2" 158 | }); 159 | deepEqual(moduleContext, { 160 | name: "logs2" 161 | }); 162 | 163 | equal(log, 41); 164 | }); 165 | 166 | var testAutorun = true; 167 | 168 | QUnit.done(function() { 169 | 170 | if (!testAutorun) { 171 | return; 172 | } 173 | 174 | testAutorun = false; 175 | 176 | module("autorun"); 177 | 178 | test("reset", 0, function() {}); 179 | 180 | moduleStart = moduleDone = 0; 181 | 182 | test("first", function(){ 183 | equal(moduleStart, 1, "test started"); 184 | equal(moduleDone, 0, "test in progress"); 185 | }); 186 | 187 | test("second", function(){ 188 | equal(moduleStart, 2, "test started"); 189 | equal(moduleDone, 1, "test in progress"); 190 | }); 191 | }); 192 | -------------------------------------------------------------------------------- /addons/themes/nv.css: -------------------------------------------------------------------------------- 1 | /** 2 | * QUnit Theme by NV 3 | * 4 | * http://docs.jquery.com/QUnit 5 | * 6 | * Copyright 2012 jQuery Foundation and other contributors 7 | * Released under the MIT license. 8 | * http://jquery.org/license 9 | */ 10 | 11 | /** Font Family and Sizes */ 12 | 13 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 14 | font-family: "Helvetica Neue", Helvetica, sans-serif; 15 | } 16 | 17 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 18 | #qunit-tests { font-size: smaller; } 19 | 20 | 21 | /** Resets */ 22 | 23 | #qunit-wrapper, #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { 24 | margin: 0; 25 | padding: 0; 26 | } 27 | 28 | 29 | /** Header */ 30 | 31 | #qunit-header { 32 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Helvetica, sans-serif; 33 | padding: 0.5em 0 0.5em 1.3em; 34 | 35 | color: #8699a4; 36 | background-color: #0d3349; 37 | 38 | font-size: 1.5em; 39 | line-height: 1em; 40 | font-weight: normal; 41 | } 42 | 43 | #qunit-header a { 44 | text-decoration: none; 45 | color: #c2ccd1; 46 | } 47 | 48 | #qunit-header a:hover, 49 | #qunit-header a:focus { 50 | color: #fff; 51 | } 52 | 53 | #qunit-header label { 54 | display: inline-block; 55 | } 56 | 57 | #qunit-banner.qunit-pass { 58 | height: 3px; 59 | } 60 | #qunit-banner.qunit-fail { 61 | height: 5px; 62 | } 63 | 64 | #qunit-testrunner-toolbar { 65 | padding: 0 0 0.5em 2em; 66 | } 67 | 68 | #qunit-testrunner-toolbar label { 69 | margin-right: 1em; 70 | } 71 | 72 | #qunit-userAgent { 73 | padding: 0.5em 0 0.5em 2.5em; 74 | font-weight: normal; 75 | color: #666; 76 | } 77 | 78 | 79 | /** Tests: Pass/Fail */ 80 | 81 | #qunit-tests { 82 | list-style-type: none; 83 | background-color: #D2E0E6; 84 | } 85 | 86 | #qunit-tests li { 87 | padding: 0.4em 0.5em 0.4em 2.5em; 88 | } 89 | 90 | #qunit-tests li strong { 91 | font-weight: normal; 92 | cursor: pointer; 93 | } 94 | 95 | #qunit-tests ol { 96 | margin: 0.5em 0 1em; 97 | background-color: #fff; 98 | } 99 | 100 | #qunit-tests table { 101 | border-collapse: collapse; 102 | margin-top: .2em; 103 | } 104 | 105 | #qunit-tests th { 106 | text-align: right; 107 | vertical-align: top; 108 | padding: 0 .5em 0 0; 109 | } 110 | 111 | #qunit-tests td { 112 | vertical-align: top; 113 | } 114 | 115 | #qunit-tests pre { 116 | margin: 0; 117 | white-space: pre-wrap; 118 | word-wrap: break-word; 119 | } 120 | 121 | #qunit-tests del { 122 | background-color: #e0f2be; 123 | color: #374e0c; 124 | text-decoration: none; 125 | } 126 | 127 | #qunit-tests ins { 128 | background-color: #ffcaca; 129 | color: #500; 130 | text-decoration: none; 131 | } 132 | 133 | /*** Test Counts */ 134 | 135 | #qunit-tests b.passed { color: #5E740B; } 136 | #qunit-tests b.failed { 137 | color: #710909; 138 | } 139 | #qunit-tests li.fail .failed { 140 | color: #E48989; 141 | } 142 | #qunit-tests li.fail .passed { 143 | color: #E3C987; 144 | } 145 | 146 | #qunit-tests li li { 147 | margin-left: 2.5em; 148 | padding: 0.7em 0.5em 0.7em 0; 149 | background-color: #fff; 150 | border-bottom: none; 151 | } 152 | 153 | #qunit-tests b.counts { 154 | font-weight: normal; 155 | } 156 | 157 | /*** Passing Styles */ 158 | 159 | #qunit-tests li li.pass { 160 | color: #5E740B; 161 | background-color: #fff; 162 | } 163 | 164 | #qunit-tests .pass { color: #2f3424; background-color: #d9dec3; } 165 | #qunit-tests .pass .module-name { color: #636b51; } 166 | 167 | #qunit-tests .pass .test-actual, 168 | #qunit-tests .pass .test-expected { color: #999999; } 169 | 170 | #qunit-banner.qunit-pass { background-color: #C6E746; } 171 | 172 | /*** Failing Styles */ 173 | 174 | #qunit-tests li li.fail { 175 | color: #710909; 176 | background-color: #fff; 177 | } 178 | 179 | #qunit-tests .fail { color: #fff; background-color: #962323; } 180 | #qunit-tests .fail .module-name, 181 | #qunit-tests .fail .counts { color: #DEC1C1; } 182 | 183 | #qunit-tests .fail .test-actual { color: #B72F2F; } 184 | #qunit-tests .fail .test-expected { color: green; } 185 | 186 | #qunit-banner.qunit-fail, 187 | #qunit-testrunner-toolbar { color: #dec1c1; background-color: #962323; } 188 | 189 | 190 | /** Footer */ 191 | 192 | #qunit-testresult { 193 | padding: 0.5em 0.5em 0.5em 2.5em; 194 | color: #333; 195 | } 196 | #qunit-testresult .module-name { 197 | font-weight: bold; 198 | } 199 | 200 | /** Fixture */ 201 | 202 | #qunit-fixture { 203 | position: absolute; 204 | top: -10000px; 205 | left: -10000px; 206 | width: 1000px; 207 | height: 1000px; 208 | } 209 | -------------------------------------------------------------------------------- /qunit/qunit.css: -------------------------------------------------------------------------------- 1 | /** 2 | * QUnit v1.10.0 - A JavaScript Unit Testing Framework 3 | * 4 | * http://qunitjs.com 5 | * 6 | * Copyright 2012 jQuery Foundation and other contributors 7 | * Released under the MIT license. 8 | * http://jquery.org/license 9 | */ 10 | 11 | /** Font Family and Sizes */ 12 | 13 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 14 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; 15 | } 16 | 17 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 18 | #qunit-tests { font-size: smaller; } 19 | 20 | 21 | /** Resets */ 22 | 23 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { 24 | margin: 0; 25 | padding: 0; 26 | } 27 | 28 | 29 | /** Header */ 30 | 31 | #qunit-header { 32 | padding: 0.5em 0 0.5em 1em; 33 | 34 | color: #8699a4; 35 | background-color: #0d3349; 36 | 37 | font-size: 1.5em; 38 | line-height: 1em; 39 | font-weight: normal; 40 | 41 | border-radius: 5px 5px 0 0; 42 | -moz-border-radius: 5px 5px 0 0; 43 | -webkit-border-top-right-radius: 5px; 44 | -webkit-border-top-left-radius: 5px; 45 | } 46 | 47 | #qunit-header a { 48 | text-decoration: none; 49 | color: #c2ccd1; 50 | } 51 | 52 | #qunit-header a:hover, 53 | #qunit-header a:focus { 54 | color: #fff; 55 | } 56 | 57 | #qunit-testrunner-toolbar label { 58 | display: inline-block; 59 | padding: 0 .5em 0 .1em; 60 | } 61 | 62 | #qunit-banner { 63 | height: 5px; 64 | } 65 | 66 | #qunit-testrunner-toolbar { 67 | padding: 0.5em 0 0.5em 2em; 68 | color: #5E740B; 69 | background-color: #eee; 70 | overflow: hidden; 71 | } 72 | 73 | #qunit-userAgent { 74 | padding: 0.5em 0 0.5em 2.5em; 75 | background-color: #2b81af; 76 | color: #fff; 77 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 78 | } 79 | 80 | #qunit-modulefilter-container { 81 | float: right; 82 | } 83 | 84 | /** Tests: Pass/Fail */ 85 | 86 | #qunit-tests { 87 | list-style-position: inside; 88 | } 89 | 90 | #qunit-tests li { 91 | padding: 0.4em 0.5em 0.4em 2.5em; 92 | border-bottom: 1px solid #fff; 93 | list-style-position: inside; 94 | } 95 | 96 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { 97 | display: none; 98 | } 99 | 100 | #qunit-tests li strong { 101 | cursor: pointer; 102 | } 103 | 104 | #qunit-tests li a { 105 | padding: 0.5em; 106 | color: #c2ccd1; 107 | text-decoration: none; 108 | } 109 | #qunit-tests li a:hover, 110 | #qunit-tests li a:focus { 111 | color: #000; 112 | } 113 | 114 | #qunit-tests ol { 115 | margin-top: 0.5em; 116 | padding: 0.5em; 117 | 118 | background-color: #fff; 119 | 120 | border-radius: 5px; 121 | -moz-border-radius: 5px; 122 | -webkit-border-radius: 5px; 123 | } 124 | 125 | #qunit-tests table { 126 | border-collapse: collapse; 127 | margin-top: .2em; 128 | } 129 | 130 | #qunit-tests th { 131 | text-align: right; 132 | vertical-align: top; 133 | padding: 0 .5em 0 0; 134 | } 135 | 136 | #qunit-tests td { 137 | vertical-align: top; 138 | } 139 | 140 | #qunit-tests pre { 141 | margin: 0; 142 | white-space: pre-wrap; 143 | word-wrap: break-word; 144 | } 145 | 146 | #qunit-tests del { 147 | background-color: #e0f2be; 148 | color: #374e0c; 149 | text-decoration: none; 150 | } 151 | 152 | #qunit-tests ins { 153 | background-color: #ffcaca; 154 | color: #500; 155 | text-decoration: none; 156 | } 157 | 158 | /*** Test Counts */ 159 | 160 | #qunit-tests b.counts { color: black; } 161 | #qunit-tests b.passed { color: #5E740B; } 162 | #qunit-tests b.failed { color: #710909; } 163 | 164 | #qunit-tests li li { 165 | padding: 5px; 166 | background-color: #fff; 167 | border-bottom: none; 168 | list-style-position: inside; 169 | } 170 | 171 | /*** Passing Styles */ 172 | 173 | #qunit-tests li li.pass { 174 | color: #3c510c; 175 | background-color: #fff; 176 | border-left: 10px solid #C6E746; 177 | } 178 | 179 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 180 | #qunit-tests .pass .test-name { color: #366097; } 181 | 182 | #qunit-tests .pass .test-actual, 183 | #qunit-tests .pass .test-expected { color: #999999; } 184 | 185 | #qunit-banner.qunit-pass { background-color: #C6E746; } 186 | 187 | /*** Failing Styles */ 188 | 189 | #qunit-tests li li.fail { 190 | color: #710909; 191 | background-color: #fff; 192 | border-left: 10px solid #EE5757; 193 | white-space: pre; 194 | } 195 | 196 | #qunit-tests > li:last-child { 197 | border-radius: 0 0 5px 5px; 198 | -moz-border-radius: 0 0 5px 5px; 199 | -webkit-border-bottom-right-radius: 5px; 200 | -webkit-border-bottom-left-radius: 5px; 201 | } 202 | 203 | #qunit-tests .fail { color: #000000; background-color: #EE5757; } 204 | #qunit-tests .fail .test-name, 205 | #qunit-tests .fail .module-name { color: #000000; } 206 | 207 | #qunit-tests .fail .test-actual { color: #EE5757; } 208 | #qunit-tests .fail .test-expected { color: green; } 209 | 210 | #qunit-banner.qunit-fail { background-color: #EE5757; } 211 | 212 | 213 | /** Result */ 214 | 215 | #qunit-testresult { 216 | padding: 0.5em 0.5em 0.5em 2.5em; 217 | 218 | color: #2b81af; 219 | background-color: #D2E0E6; 220 | 221 | border-bottom: 1px solid white; 222 | } 223 | #qunit-testresult .module-name { 224 | font-weight: bold; 225 | } 226 | 227 | /** Fixture */ 228 | 229 | #qunit-fixture { 230 | position: absolute; 231 | top: -10000px; 232 | left: -10000px; 233 | width: 1000px; 234 | height: 1000px; 235 | } 236 | -------------------------------------------------------------------------------- /addons/junitlogger/junitlogger.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var count = 0, suiteCount = 0, currentSuite, currentTest, suites = [], assertCount, start, results = {failed:0, passed:0, total:0, time:0}; 3 | 4 | QUnit.jUnitReport = function(data) { 5 | // Gets called when a report is generated 6 | }; 7 | 8 | QUnit.moduleStart(function(data) { 9 | currentSuite = { 10 | name: data.name, 11 | tests: [], 12 | failures: 0, 13 | time: 0, 14 | stdout : '', 15 | stderr : '' 16 | }; 17 | 18 | suites.push(currentSuite); 19 | }); 20 | 21 | QUnit.moduleDone(function(data) { 22 | }); 23 | 24 | QUnit.testStart(function(data) { 25 | if(!start){ start = new Date(); } 26 | 27 | assertCount = 0; 28 | 29 | currentTest = { 30 | name: data.name, 31 | failures: [], 32 | start: new Date() 33 | }; 34 | 35 | // Setup default suite if no module was specified 36 | if (!currentSuite) { 37 | currentSuite = { 38 | name: "default", 39 | tests: [], 40 | failures: 0, 41 | time: 0, 42 | stdout : '', 43 | stderr : '' 44 | }; 45 | 46 | suites.push(currentSuite); 47 | } 48 | 49 | currentSuite.tests.push(currentTest); 50 | }); 51 | 52 | QUnit.testDone(function(data) { 53 | currentTest.failed = data.failed; 54 | currentTest.total = data.total; 55 | currentSuite.failures += data.failed; 56 | 57 | results.failed += data.failed; 58 | results.passed += data.passed; 59 | results.total += data.total; 60 | }); 61 | 62 | QUnit.log(function(data) { 63 | assertCount++; 64 | 65 | if (!data.result) { 66 | currentTest.failures.push(data.message); 67 | 68 | // Add log message of failure to make it easier to find in jenkins UI 69 | currentSuite.stdout += '[' + currentSuite.name + ', ' + currentTest.name + ', ' + assertCount + '] ' + data.message + '\n'; 70 | } 71 | }); 72 | 73 | QUnit.done(function(data) { 74 | function ISODateString(d) { 75 | function pad(n) { 76 | return n < 10 ? '0' + n : n; 77 | } 78 | 79 | return d.getUTCFullYear() + '-' + 80 | pad(d.getUTCMonth() + 1)+'-' + 81 | pad(d.getUTCDate()) + 'T' + 82 | pad(d.getUTCHours()) + ':' + 83 | pad(d.getUTCMinutes()) + ':' + 84 | pad(d.getUTCSeconds()) + 'Z'; 85 | } 86 | 87 | // Generate XML report 88 | var i, ti, fi, test, suite, 89 | xmlWriter = new XmlWriter({ 90 | linebreak_at : "testsuites,testsuite,testcase,failure,system-out,system-err" 91 | }), 92 | now = new Date(); 93 | 94 | xmlWriter.start('testsuites'); 95 | 96 | for (i = 0; i < suites.length; i++) { 97 | suite = suites[i]; 98 | 99 | // Calculate time 100 | for (ti = 0; ti < suite.tests.length; ti++) { 101 | test = suite.tests[ti]; 102 | 103 | test.time = (now.getTime() - test.start.getTime()) / 1000; 104 | suite.time += test.time; 105 | } 106 | 107 | xmlWriter.start('testsuite', { 108 | id: "" + i, 109 | name: suite.name, 110 | errors: "0", 111 | failures: suite.failures, 112 | hostname: "localhost", 113 | tests: suite.tests.length, 114 | time: Math.round(suite.time * 1000) / 1000, 115 | timestamp: ISODateString(now) 116 | }); 117 | 118 | for (ti = 0; ti < suite.tests.length; ti++) { 119 | test = suite.tests[ti]; 120 | 121 | xmlWriter.start('testcase', { 122 | name: test.name, 123 | total: test.total, 124 | failed: test.failed, 125 | time: Math.round(test.time * 1000) / 1000 126 | }); 127 | 128 | for (fi = 0; fi < test.failures.length; fi++) { 129 | xmlWriter.start('failure', {type: "AssertionFailedError", message: test.failures[fi]}, true); 130 | } 131 | 132 | xmlWriter.end('testcase'); 133 | } 134 | 135 | if (suite.stdout) { 136 | xmlWriter.start('system-out'); 137 | xmlWriter.cdata('\n' + suite.stdout); 138 | xmlWriter.end('system-out'); 139 | } 140 | 141 | if (suite.stderr) { 142 | xmlWriter.start('system-err'); 143 | xmlWriter.cdata('\n' + suite.stderr); 144 | xmlWriter.end('system-err'); 145 | } 146 | 147 | xmlWriter.end('testsuite'); 148 | } 149 | 150 | xmlWriter.end('testsuites'); 151 | 152 | results.time = new Date() - start; 153 | 154 | QUnit.jUnitReport({ 155 | results:results, 156 | xml: xmlWriter.getString() 157 | }); 158 | }); 159 | 160 | function XmlWriter(settings) { 161 | function addLineBreak(name) { 162 | if (lineBreakAt[name] && data[data.length - 1] !== '\n') { 163 | data.push('\n'); 164 | } 165 | } 166 | 167 | function makeMap(items, delim, map) { 168 | var i; 169 | 170 | items = items || []; 171 | 172 | if (typeof(items) === "string") { 173 | items = items.split(','); 174 | } 175 | 176 | map = map || {}; 177 | 178 | i = items.length; 179 | while (i--) { 180 | map[items[i]] = {}; 181 | } 182 | 183 | return map; 184 | } 185 | 186 | function encode(text) { 187 | var baseEntities = { 188 | '"' : '"', 189 | "'" : ''', 190 | '<' : '<', 191 | '>' : '>', 192 | '&' : '&' 193 | }; 194 | 195 | return ('' + text).replace(/[<>&\"\']/g, function(chr) { 196 | return baseEntities[chr] || chr; 197 | }); 198 | } 199 | 200 | var data = [], stack = [], lineBreakAt; 201 | 202 | settings = settings || {}; 203 | lineBreakAt = makeMap(settings.linebreak_at || 'mytag'); 204 | 205 | this.start = function(name, attrs, empty) { 206 | if (!empty) { 207 | stack.push(name); 208 | } 209 | 210 | data.push('<', name); 211 | 212 | for (var aname in attrs) { 213 | data.push(" " + encode(aname), '="', encode(attrs[aname]), '"'); 214 | } 215 | 216 | data.push(empty ? ' />' : '>'); 217 | addLineBreak(name); 218 | }; 219 | 220 | this.end = function(name) { 221 | stack.pop(); 222 | addLineBreak(name); 223 | data.push(''); 224 | addLineBreak(name); 225 | }; 226 | 227 | this.text = function(text) { 228 | data.push(encode(text)); 229 | }; 230 | 231 | this.cdata = function(text) { 232 | data.push(''); 233 | }; 234 | 235 | this.comment = function(text) { 236 | data.push(''); 237 | }; 238 | 239 | this.pi = function(name, text) { 240 | if (text) { 241 | data.push('\n'); 242 | } else { 243 | data.push('\n'); 244 | } 245 | }; 246 | 247 | this.doctype = function(text) { 248 | data.push('\n'); 249 | }; 250 | 251 | this.getString = function() { 252 | for (var i = stack.length - 1; i >= 0; i--) { 253 | this.end(stack[i]); 254 | } 255 | 256 | stack = []; 257 | 258 | return data.join('').replace(/\n$/, ''); 259 | }; 260 | 261 | this.reset = function() { 262 | data = []; 263 | stack = []; 264 | }; 265 | 266 | this.pi(settings.xmldecl || 'xml version="1.0" encoding="UTF-8"'); 267 | } 268 | })(); -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | test("module without setup/teardown (default)", function() { 2 | expect(1); 3 | ok(true); 4 | }); 5 | 6 | test("expect in test", 3, function() { 7 | ok(true); 8 | ok(true); 9 | ok(true); 10 | }); 11 | 12 | test("expect in test", 1, function() { 13 | ok(true); 14 | }); 15 | 16 | test("expect query and multiple issue", function() { 17 | expect(2); 18 | ok(true); 19 | var expected = expect(); 20 | equal(expected, 2); 21 | expect(expected + 1); 22 | ok(true); 23 | }); 24 | 25 | QUnit.module("assertion helpers"); 26 | 27 | QUnit.test( "QUnit.assert compatibility", function( assert ) { 28 | QUnit.expect(4); 29 | 30 | assert.ok( true, "Calling method on `assert` argument to test() callback" ); 31 | 32 | // Should also work, although not documented 33 | QUnit.assert.ok( true, "Calling method on QUnit.assert object" ); 34 | 35 | // Test compatibility aliases 36 | QUnit.ok( true, "Calling aliased method in QUnit root object" ); 37 | ok( true, "Calling aliased function in global namespace" ); 38 | }); 39 | 40 | module("setup test", { 41 | setup: function() { 42 | ok(true); 43 | } 44 | }); 45 | 46 | test("module with setup", function() { 47 | expect(2); 48 | ok(true); 49 | }); 50 | 51 | test("module with setup, expect in test call", 2, function() { 52 | ok(true); 53 | }); 54 | 55 | var state; 56 | 57 | module("setup/teardown test", { 58 | setup: function() { 59 | state = true; 60 | ok(true); 61 | x = 1; 62 | }, 63 | teardown: function() { 64 | ok(true); 65 | // can introduce and delete globals in setup/teardown 66 | // without noglobals sounding the alarm 67 | delete x; 68 | } 69 | }); 70 | 71 | test("module with setup/teardown", function() { 72 | expect(3); 73 | ok(true); 74 | }); 75 | 76 | module("setup/teardown test 2"); 77 | 78 | test("module without setup/teardown", function() { 79 | expect(1); 80 | ok(true); 81 | }); 82 | 83 | 84 | 85 | var orgDate; 86 | 87 | module("Date test", { 88 | setup: function() { 89 | orgDate = Date; 90 | Date = function () { 91 | ok( false, 'QUnit should internally be independant from Date-related manipulation and testing' ); 92 | return new orgDate(); 93 | }; 94 | }, 95 | teardown: function() { 96 | Date = orgDate; 97 | } 98 | }); 99 | 100 | test("sample test for Date test", function () { 101 | expect(1); 102 | ok(true); 103 | }); 104 | 105 | if (typeof setTimeout !== 'undefined') { 106 | state = 'fail'; 107 | 108 | module("teardown and stop", { 109 | teardown: function() { 110 | equal(state, "done", "Test teardown."); 111 | } 112 | }); 113 | 114 | test("teardown must be called after test ended", function() { 115 | expect(1); 116 | stop(); 117 | setTimeout(function() { 118 | state = "done"; 119 | start(); 120 | }, 13); 121 | }); 122 | 123 | test("parameter passed to stop increments semaphore n times", function() { 124 | expect(1); 125 | stop(3); 126 | setTimeout(function() { 127 | state = "not enough starts"; 128 | start(), start(); 129 | }, 13); 130 | setTimeout(function() { 131 | state = "done"; 132 | start(); 133 | }, 15); 134 | }); 135 | 136 | test("parameter passed to start decrements semaphore n times", function() { 137 | expect(1); 138 | stop(), stop(), stop(); 139 | setTimeout(function() { 140 | state = "done"; 141 | start(3); 142 | }, 18); 143 | }); 144 | 145 | module("async setup test", { 146 | setup: function() { 147 | stop(); 148 | setTimeout(function(){ 149 | ok(true); 150 | start(); 151 | }, 500); 152 | } 153 | }); 154 | 155 | asyncTest("module with async setup", function() { 156 | expect(2); 157 | ok(true); 158 | start(); 159 | }); 160 | 161 | module("async teardown test", { 162 | teardown: function() { 163 | stop(); 164 | setTimeout(function(){ 165 | ok(true); 166 | start(); 167 | }, 500); 168 | } 169 | }); 170 | 171 | asyncTest("module with async teardown", function() { 172 | expect(2); 173 | ok(true); 174 | start(); 175 | }); 176 | 177 | module("asyncTest"); 178 | 179 | asyncTest("asyncTest", function() { 180 | expect(2); 181 | ok(true); 182 | setTimeout(function() { 183 | state = "done"; 184 | ok(true); 185 | start(); 186 | }, 13); 187 | }); 188 | 189 | asyncTest("asyncTest", 2, function() { 190 | ok(true); 191 | setTimeout(function() { 192 | state = "done"; 193 | ok(true); 194 | start(); 195 | }, 13); 196 | }); 197 | 198 | test("sync", 2, function() { 199 | stop(); 200 | setTimeout(function() { 201 | ok(true); 202 | start(); 203 | }, 13); 204 | stop(); 205 | setTimeout(function() { 206 | ok(true); 207 | start(); 208 | }, 125); 209 | }); 210 | 211 | test("test synchronous calls to stop", 2, function() { 212 | stop(); 213 | setTimeout(function(){ 214 | ok(true, 'first'); 215 | start(); 216 | stop(); 217 | setTimeout(function(){ 218 | ok(true, 'second'); 219 | start(); 220 | }, 150); 221 | }, 150); 222 | }); 223 | } 224 | 225 | module("save scope", { 226 | setup: function() { 227 | this.foo = "bar"; 228 | }, 229 | teardown: function() { 230 | deepEqual(this.foo, "bar"); 231 | } 232 | }); 233 | test("scope check", function() { 234 | expect(2); 235 | deepEqual(this.foo, "bar"); 236 | }); 237 | 238 | module("simple testEnvironment setup", { 239 | foo: "bar", 240 | bugid: "#5311" // example of meta-data 241 | }); 242 | test("scope check", function() { 243 | deepEqual(this.foo, "bar"); 244 | }); 245 | test("modify testEnvironment",function() { 246 | expect(0); 247 | this.foo="hamster"; 248 | }); 249 | test("testEnvironment reset for next test",function() { 250 | deepEqual(this.foo, "bar"); 251 | }); 252 | 253 | module("testEnvironment with object", { 254 | options:{ 255 | recipe:"soup", 256 | ingredients:["hamster","onions"] 257 | } 258 | }); 259 | test("scope check", function() { 260 | deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ; 261 | }); 262 | test("modify testEnvironment",function() { 263 | expect(0); 264 | // since we do a shallow copy, the testEnvironment can be modified 265 | this.options.ingredients.push("carrots"); 266 | }); 267 | test("testEnvironment reset for next test",function() { 268 | deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ; 269 | }); 270 | 271 | 272 | module("testEnvironment tests"); 273 | 274 | function makeurl() { 275 | var testEnv = QUnit.current_testEnvironment; 276 | var url = testEnv.url || 'http://example.com/search'; 277 | var q = testEnv.q || 'a search test'; 278 | return url + '?q='+encodeURIComponent(q); 279 | } 280 | 281 | test("makeurl working",function() { 282 | equal( QUnit.current_testEnvironment, this, 'The current testEnvironment is global'); 283 | equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment'); 284 | }); 285 | 286 | module("testEnvironment with makeurl settings", { 287 | url: 'http://google.com/', 288 | q: 'another_search_test' 289 | }); 290 | test("makeurl working with settings from testEnvironment", function() { 291 | equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to from the url'); 292 | }); 293 | 294 | module("jsDump"); 295 | test("jsDump output", function() { 296 | equal( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" ); 297 | equal( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"left\": 0,\n \"top\": 5\n}" ); 298 | if (typeof document !== 'undefined' && document.getElementById("qunit-header")) { 299 | equal( QUnit.jsDump.parse(document.getElementById("qunit-header")), "

" ); 300 | equal( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n

\n]" ); 301 | } 302 | }); 303 | 304 | module("assertions"); 305 | test("raises",function() { 306 | function CustomError( message ) { 307 | this.message = message; 308 | } 309 | 310 | CustomError.prototype.toString = function() { 311 | return this.message; 312 | }; 313 | 314 | throws( 315 | function() { 316 | throw "my error" 317 | } 318 | ); 319 | 320 | throws( 321 | function() { 322 | throw "my error" 323 | }, 324 | "simple string throw, no 'expected' value given" 325 | ); 326 | 327 | throws( 328 | function() { 329 | throw new CustomError(); 330 | }, 331 | CustomError, 332 | 'thrown error is an instance of CustomError' 333 | ); 334 | 335 | throws( 336 | function() { 337 | throw new CustomError("some error description"); 338 | }, 339 | /description/, 340 | "use a regex to match against the stringified error" 341 | ); 342 | 343 | throws( 344 | function() { 345 | throw new CustomError("some error description"); 346 | }, 347 | function( err ) { 348 | if ( (err instanceof CustomError) && /description/.test(err) ) { 349 | return true; 350 | } 351 | }, 352 | "custom validation function" 353 | ); 354 | 355 | throws( 356 | function() { 357 | ( window.execScript || function( data ) { 358 | window["eval"].call( window, data ); 359 | })( "throw 'error'" ); 360 | }, 361 | 'globally-executed errors caught' 362 | ); 363 | 364 | this.CustomError = CustomError; 365 | 366 | throws( 367 | function() { 368 | throw new this.CustomError("some error description"); 369 | }, 370 | /description/, 371 | "throw error from property of 'this' context" 372 | ); 373 | 374 | raises( 375 | function() { 376 | throw "error" 377 | }, 378 | "simple throw, asserting with deprecated raises() function" 379 | ); 380 | 381 | }); 382 | 383 | if (typeof document !== "undefined") { 384 | 385 | module("fixture"); 386 | test("setup", function() { 387 | expect(0); 388 | document.getElementById("qunit-fixture").innerHTML = "foobar"; 389 | }); 390 | test("basics", function() { 391 | equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" ); 392 | }); 393 | 394 | test("running test name displayed", function() { 395 | expect(2); 396 | 397 | var displaying = document.getElementById("qunit-testresult"); 398 | 399 | ok( /running test name displayed/.test(displaying.innerHTML), "Expect test name to be found in displayed text" ); 400 | ok( /fixture/.test(displaying.innerHTML), "Expect module name to be found in displayed text" ); 401 | }); 402 | 403 | } 404 | 405 | module("custom assertions"); 406 | (function() { 407 | function mod2(value, expected, message) { 408 | var actual = value % 2; 409 | QUnit.push(actual == expected, actual, expected, message); 410 | } 411 | test("mod2", function() { 412 | mod2(2, 0, "2 % 2 == 0"); 413 | mod2(3, 1, "3 % 2 == 1"); 414 | }); 415 | })(); 416 | 417 | 418 | module("recursions"); 419 | 420 | function Wrap(x) { 421 | this.wrap = x; 422 | if (x == undefined) this.first = true; 423 | } 424 | 425 | function chainwrap(depth, first, prev) { 426 | depth = depth || 0; 427 | var last = prev || new Wrap(); 428 | first = first || last; 429 | 430 | if (depth == 1) { 431 | first.wrap = last; 432 | } 433 | if (depth > 1) { 434 | last = chainwrap(depth-1, first, new Wrap(last)); 435 | } 436 | 437 | return last; 438 | } 439 | 440 | test("check jsDump recursion", function() { 441 | expect(4); 442 | 443 | var noref = chainwrap(0); 444 | var nodump = QUnit.jsDump.parse(noref); 445 | equal(nodump, '{\n "first": true,\n "wrap": undefined\n}'); 446 | 447 | var selfref = chainwrap(1); 448 | var selfdump = QUnit.jsDump.parse(selfref); 449 | equal(selfdump, '{\n "first": true,\n "wrap": recursion(-1)\n}'); 450 | 451 | var parentref = chainwrap(2); 452 | var parentdump = QUnit.jsDump.parse(parentref); 453 | equal(parentdump, '{\n "wrap": {\n "first": true,\n "wrap": recursion(-2)\n }\n}'); 454 | 455 | var circref = chainwrap(10); 456 | var circdump = QUnit.jsDump.parse(circref); 457 | ok(new RegExp("recursion\\(-10\\)").test(circdump), "(" +circdump + ") should show -10 recursion level"); 458 | }); 459 | 460 | test("check (deep-)equal recursion", function() { 461 | var noRecursion = chainwrap(0); 462 | equal(noRecursion, noRecursion, "I should be equal to me."); 463 | deepEqual(noRecursion, noRecursion, "... and so in depth."); 464 | 465 | var selfref = chainwrap(1); 466 | equal(selfref, selfref, "Even so if I nest myself."); 467 | deepEqual(selfref, selfref, "... into the depth."); 468 | 469 | var circref = chainwrap(10); 470 | equal(circref, circref, "Or hide that through some levels of indirection."); 471 | deepEqual(circref, circref, "... and checked on all levels!"); 472 | }); 473 | 474 | 475 | test('Circular reference with arrays', function() { 476 | 477 | // pure array self-ref 478 | var arr = []; 479 | arr.push(arr); 480 | 481 | var arrdump = QUnit.jsDump.parse(arr); 482 | 483 | equal(arrdump, '[\n recursion(-1)\n]'); 484 | equal(arr, arr[0], 'no endless stack when trying to dump arrays with circular ref'); 485 | 486 | 487 | // mix obj-arr circular ref 488 | var obj = {}; 489 | var childarr = [obj]; 490 | obj.childarr = childarr; 491 | 492 | var objdump = QUnit.jsDump.parse(obj); 493 | var childarrdump = QUnit.jsDump.parse(childarr); 494 | 495 | equal(objdump, '{\n "childarr": [\n recursion(-2)\n ]\n}'); 496 | equal(childarrdump, '[\n {\n "childarr": recursion(-2)\n }\n]'); 497 | 498 | equal(obj.childarr, childarr, 'no endless stack when trying to dump array/object mix with circular ref'); 499 | equal(childarr[0], obj, 'no endless stack when trying to dump array/object mix with circular ref'); 500 | 501 | }); 502 | 503 | 504 | test('Circular reference - test reported by soniciq in #105', function() { 505 | var MyObject = function() {}; 506 | MyObject.prototype.parent = function(obj) { 507 | if (obj === undefined) { return this._parent; } 508 | this._parent = obj; 509 | }; 510 | MyObject.prototype.children = function(obj) { 511 | if (obj === undefined) { return this._children; } 512 | this._children = obj; 513 | }; 514 | 515 | var a = new MyObject(), 516 | b = new MyObject(); 517 | 518 | var barr = [b]; 519 | a.children(barr); 520 | b.parent(a); 521 | 522 | equal(a.children(), barr); 523 | deepEqual(a.children(), [b]); 524 | }); 525 | 526 | (function() { 527 | var reset = QUnit.reset; 528 | module("reset"); 529 | test("reset runs assertions", function() { 530 | expect(0); 531 | QUnit.reset = function() { 532 | ok( false, "reset should not modify test status" ); 533 | reset.apply( this, arguments ); 534 | }; 535 | }); 536 | test("reset runs assertions, cleanup", function() { 537 | expect(0); 538 | QUnit.reset = reset; 539 | }); 540 | })(); 541 | 542 | if (typeof setTimeout !== 'undefined') { 543 | function testAfterDone(){ 544 | var testName = "ensure has correct number of assertions"; 545 | 546 | function secondAfterDoneTest(){ 547 | QUnit.config.done = []; 548 | //QUnit.done = function(){}; 549 | //because when this does happen, the assertion count parameter doesn't actually 550 | //work we use this test to check the assertion count. 551 | module("check previous test's assertion counts"); 552 | test('count previous two test\'s assertions', function(){ 553 | var spans = document.getElementsByTagName('span'), 554 | tests = [], 555 | countNodes; 556 | 557 | //find these two tests 558 | for (var i = 0; i < spans.length; i++) { 559 | if (spans[i].innerHTML.indexOf(testName) !== -1) { 560 | tests.push(spans[i]); 561 | } 562 | } 563 | 564 | //walk dom to counts 565 | countNodes = tests[0].nextSibling.nextSibling.getElementsByTagName('b'); 566 | equal(countNodes[1].innerHTML, "99"); 567 | countNodes = tests[1].nextSibling.nextSibling.getElementsByTagName('b'); 568 | equal(countNodes[1].innerHTML, "99"); 569 | }); 570 | } 571 | QUnit.config.done = []; 572 | QUnit.done(secondAfterDoneTest); 573 | 574 | module("Synchronous test after load of page"); 575 | 576 | asyncTest('Async test', function(){ 577 | start(); 578 | for (var i = 1; i < 100; i++) { 579 | ok(i); 580 | } 581 | }); 582 | 583 | test(testName, 99, function(){ 584 | for (var i = 1; i < 100; i++) { 585 | ok(i); 586 | } 587 | }); 588 | 589 | //we need two of these types of tests in order to ensure that assertions 590 | //don't move between tests. 591 | test(testName + ' 2', 99, function(){ 592 | for (var i = 1; i < 100; i++) { 593 | ok(i); 594 | } 595 | }); 596 | 597 | 598 | } 599 | 600 | QUnit.done(testAfterDone); 601 | 602 | } 603 | -------------------------------------------------------------------------------- /addons/themes/gabe.css: -------------------------------------------------------------------------------- 1 | /** 2 | * QUnit Theme by Gabe Hendry 3 | * 4 | * http://docs.jquery.com/QUnit 5 | * 6 | * Copyright 2012 jQuery Foundation and other contributors 7 | * Released under the MIT license. 8 | * http://jquery.org/license 9 | */ 10 | 11 | /** General Styles and Page Sturcture */ 12 | body { 13 | font-family:Arial, 'sans serif'; 14 | padding:20px 20px 0 20px; 15 | position:relative; 16 | } 17 | 18 | h1, h2, h3, h4, h5, h6, #qunit-header, #qunit-banner { 19 | font-family:Calibri, Arial, 'sans-serif'; 20 | } 21 | 22 | h2 #qunit-tests, h2 #qunit-testrunner-toolbar, h2 #qunit-userAgent, #qunit-testresult { 23 | font-family: Arial, 'sans-serif'; 24 | } 25 | 26 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 27 | #qunit-tests { font-size: smaller; } 28 | 29 | 30 | /** Resets */ 31 | 32 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { 33 | margin: 0; 34 | padding: 0; 35 | } 36 | 37 | 38 | /** Headers */ 39 | 40 | #qunit-header { 41 | padding: 10px 0px 25px 0px; 42 | color: #3B73B9; 43 | font-size: 1.8em; 44 | font-weight: normal; 45 | height:2em; 46 | } 47 | 48 | #qunit-header a { 49 | text-decoration: none; 50 | color: #3B73B9; 51 | font-weight:bold; 52 | padding-right:22px; 53 | float:left; 54 | 55 | } 56 | 57 | #qunit-header label { 58 | font-size:14px; 59 | color:#6BC9ED; 60 | float:right; 61 | font-family:Arial, 'sans-serif'; 62 | display: inline-block; 63 | } 64 | 65 | #qunit-header a + label:after { 66 | content: ' }'; 67 | } 68 | 69 | #qunit-header label + label { 70 | margin-right:8px; 71 | } 72 | 73 | #qunit-header a:hover, #qunit-header a:focus { 74 | color: #3B73B9; 75 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAcCAYAAABoMT8aAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpERkFDNTFBMjMwREYxMUUxQTA3RjlDQkNDQzY3MkI4MCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpERkFDNTFBMTMwREYxMUUxQTA3RjlDQkNDQzY3MkI4MCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PjKftvwAAAFqSURBVHja5NTNKwVRHMbxey9X3rrXStlY2ljJRiQLGytLIkUpIks7lIUFC9laCX+DhUiSlMRdsFBSdkqSt4u8ju+vnqkxZriZheTUp1NzzvxmzjnPTNxxnFiUlohFbL9fIL9xeOUf7EEiSgEbf8XUTwv04A59mIuyB2VowyqKvytQjkU8YwaFul6CJmQ+5MB38zSGUIAs8vCi3loc6bA3mECvJl2o0Jhn/B47qAorMIgU9lGJBc/YDZbQgNugAt1I4gGtepq1ZTxiHu2B34L6LpRiD6ee8UPUqfe2lPbl0i1Qoz4T8JCgm89hf6IKdwnX6tM5ZGIEb1py1i2wporNORToUDa2LStugVntdPKr3GvMUnmFUe8p2No3FNOBkCIWsn7NOcC6Pwd2EicoUiZsnVvYxZNutpM601F/CpIFpNazH5bIel1LqOAmqrWEwG/BirQorp3KgL3yMSZxFBYkf7OJ43/jp/ouwAB8JktCUeXXIAAAAABJRU5ErkJggg==') center right no-repeat; 76 | } 77 | 78 | h2, p { 79 | padding: 10px 0 10px 0; 80 | margin:0; 81 | font-size:1.3em; 82 | } 83 | 84 | p { 85 | padding-top:0; 86 | font-size:small; 87 | color:#7B7979; 88 | line-height:1.6em; 89 | } 90 | 91 | h2#qunit-banner { 92 | height: 16px; 93 | padding:5px 5px 5px 25px; 94 | line-height:16px; 95 | margin:0px 0 15px 0; 96 | border-radius: 5px; 97 | -moz-border-radius: 5px; 98 | -webkit-border-radius: 5px; 99 | background-position:0px; 100 | background-repeat:no-repeat; 101 | font-size:1em; 102 | font-weight:normal; 103 | } 104 | 105 | h2#qunit-banner.qunit-pass { 106 | background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjc1RjgyNEY5MzE2NzExRTFCQTA0RTIzMEVFNkY4ODM2IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjc1RjgyNEZBMzE2NzExRTFCQTA0RTIzMEVFNkY4ODM2Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NzVGODI0RjczMTY3MTFFMUJBMDRFMjMwRUU2Rjg4MzYiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NzVGODI0RjgzMTY3MTFFMUJBMDRFMjMwRUU2Rjg4MzYiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4C94F5AAAAwklEQVR42mL8//8/AyWAiYFCQLEBLOW7GEnVYwzEaUC8B4hXs5CoWRCIVwGxEtQQE1K9ANMMN5AUAzqA2AWJ/x6IzxJrAMi55WhiriBDYAYoEQi0DjSxdJDtsGgESd4F4jNYDAIF2m4oDQOzoBieDsqRbDoDpWEAXfMeqO0oCWkPmo1noH6eiWbYPSAOw5YSQYKr0cRnQg1BDvEwKI1hAEyyAk9AVsACDV9e6MRhSydyoBHKTKuh8bsHSTM+lzEABBgAXD0oIFydPtEAAAAASUVORK5CYII='); 107 | color:#76B900; 108 | } 109 | 110 | h2#qunit-banner.qunit-pass:after { 111 | content:'Congrats! All of your tests passed!'; 112 | } 113 | 114 | h2#qunit-banner.qunit-fail { 115 | background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjU5QUIzNEU2MzE2NzExRTE4ODc3OEVFNEY2NzhDMjM4IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjU5QUIzNEU3MzE2NzExRTE4ODc3OEVFNEY2NzhDMjM4Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NTlBQjM0RTQzMTY3MTFFMTg4Nzc4RUU0RjY3OEMyMzgiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NTlBQjM0RTUzMTY3MTFFMTg4Nzc4RUU0RjY3OEMyMzgiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz46NEjgAAAAzElEQVR42mL8//8/AyWABUS8N1EFUS5AfA+KcQFBIE6DsjsFz9yGGAAEu6EGgEA6EM/CoRmkzhiJX8EE5bggKZyJZAsuzQwwNhMOp6IbsgpNM9jn8DCAOnsmFkNgNrlg0dyJbMAsNE0MOPgwza5AfBbdC7OgLsEHUDRjCwNChqBoxhWIxngMQI8dDAPKsSlCM2AmLgNAkh04/I3TECZcJiNFrys+Q2AGhOLQPAsaaLgMwZkS0fMDLkPgBqzGoxnZEBMg3gM1CBzdAAEGABpTMr+umvCXAAAAAElFTkSuQmCC'); 116 | color:#ee3324; 117 | } 118 | 119 | h2#qunit-banner.qunit-fail:after { 120 | content:'Oops! One or more tests failed!'; 121 | } 122 | 123 | /** Test Runner Result Styles */ 124 | 125 | #qunit-testrunner-toolbar { 126 | position:absolute; 127 | top:55px; 128 | right:20px; 129 | color:#6BC9ED; 130 | font-size:14px; 131 | } 132 | 133 | #qunit-testrunner-toolbar:after { 134 | content:' }'; 135 | } 136 | 137 | h2#qunit-userAgent { 138 | padding: 0; 139 | color: #7B7979; 140 | border:0; 141 | font-size:small; 142 | font-family: Arial, 'sans-serif'; 143 | font-weight:normal; 144 | font-style:italic; 145 | } 146 | 147 | h2#qunit-userAgent:before { 148 | content:'User Agents: '; 149 | } 150 | 151 | 152 | /** Tests: Pass/Fail */ 153 | 154 | #qunit-tests { 155 | list-style-position: inside; 156 | list-style-type:none; 157 | } 158 | 159 | #qunit-tests li { 160 | padding: 4px 10px; 161 | list-style-position:outside; 162 | border-radius: 5px; 163 | -moz-border-radius: 5px; 164 | -webkit-border-radius: 5px; 165 | margin-bottom:5px; 166 | position:relative; 167 | *zoom:1; 168 | list-style-type:none; 169 | } 170 | 171 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { 172 | display: none; 173 | } 174 | 175 | #qunit-tests li strong { 176 | cursor: pointer; 177 | } 178 | 179 | #qunit-tests li a { 180 | display:block; 181 | position:absolute; 182 | right:10px; 183 | padding:0px 16px 0 0; 184 | font-size:0.8em; 185 | background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAYCAYAAADOMhxqAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpENEZDRDdDQTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpENEZDRDdDOTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MDRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PpE8SAQAAAD3SURBVHjaYsw5+YYBC5gGxN+BuBhdgoUBO1AFYlMgFgXiOGQJJjSFrEDcC8RaQMwPxEFAvBuXDSDFP6D4F1SMG4gtgFgBiB+g2/ATiL8C8UIgPgMV+wvEujDFyBoWQRVPB+IsqOa3QCyFrBhZgysQMwLxFCjfB4hFgPgVlH8DiOcha/jHgBu0ALEMEH9G1rAXqikHi4ZkIP4DxEuQNaQBMReUngjEdkAcDPU8KKROAPFp5GAFBSUPNHZToZEFM+wsEHtgiziQJmYg7gPiy0B8HIiTgNgRX0yD/FFzYdXZK0B8Fchei5GWgBI40xJQbjQtjdi0BBBgAAsUYVWmfe1CAAAAAElFTkSuQmCC') bottom right no-repeat; 186 | color: #3b73b9; 187 | text-decoration: none; 188 | height:12px; 189 | top:5px; 190 | } 191 | #qunit-tests li a:hover, 192 | #qunit-tests li a:focus { 193 | color: #6bc9ed; 194 | background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAYCAYAAADOMhxqAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpENEZDRDdDQTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpENEZDRDdDOTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MDRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PpE8SAQAAAD3SURBVHjaYsw5+YYBC5gGxN+BuBhdgoUBO1AFYlMgFgXiOGQJJjSFrEDcC8RaQMwPxEFAvBuXDSDFP6D4F1SMG4gtgFgBiB+g2/ATiL8C8UIgPgMV+wvEujDFyBoWQRVPB+IsqOa3QCyFrBhZgysQMwLxFCjfB4hFgPgVlH8DiOcha/jHgBu0ALEMEH9G1rAXqikHi4ZkIP4DxEuQNaQBMReUngjEdkAcDPU8KKROAPFp5GAFBSUPNHZToZEFM+wsEHtgiziQJmYg7gPiy0B8HIiTgNgRX0yD/FFzYdXZK0B8Fchei5GWgBI40xJQbjQtjdi0BBBgAAsUYVWmfe1CAAAAAElFTkSuQmCC') top right no-repeat; 195 | } 196 | #qunit-tests li.pass strong > span {color:#76B900;} 197 | #qunit-tests li.pass strong:first-child { 198 | padding-left:20px; 199 | background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozODgyNDY5QzMxN0ExMUUxOTdFMkVCQkNENjFBMjc3RSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozODgyNDY5QjMxN0ExMUUxOTdFMkVCQkNENjFBMjc3RSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pv7qI08AAAClSURBVHjaYvz//z8DKYClfBcjMeqUgFgQiM+yEKEYpHA3VFMYExEaVkEVg20ipKEDiF2g7LNAPIsJaqUgFsVpQFwOZb8H4nQQzQR13zuoAhgwhpoOA2FQGxiYkNw3E4phnoTZWgHEe2A6maC63yM54y6S4llA3InsTiaobhOYlUiKz0JNZ0DXAAL3gNgViFcjeRLZZkRMI7FhioyhBrzHFs4AAQYAz08iXvWgossAAAAASUVORK5CYII=') center left no-repeat; 200 | } 201 | 202 | #qunit-tests li.fail strong > span {color:#EE3324;} 203 | #qunit-tests li.fail strong:first-child { 204 | padding-left:20px; 205 | background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo0MzNBNEM0QzMxN0ExMUUxQjk0MUYyOEJCODA0OTM1OSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo0MzNBNEM0QjMxN0ExMUUxQjk0MUYyOEJCODA0OTM1OSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PnO7dSIAAACtSURBVHjaYnxnrMIABEpA/B6K0YEgEBsD8VnBM7ffM0E5d6HYGIvi3UiYgQkqiCyJrAmZbwzTcBaKYZrOAHEaEM9E05wOIlig7nZFM20mmtM6gXgWzAYGJE1nsXgapLACxmFCkniPQwOKGLKGmVC3owMUcZiGDjTFs9BMhmuCxUM5muJ0qJ9Wo2lCcRII7IEFH9RPYbDQgaUCFqjVYdDkMQuLH9Khau6BOAABBgDmhyuetyQ3ywAAAABJRU5ErkJggg==') center left no-repeat; 206 | } 207 | 208 | #qunit-tests li ol { 209 | margin:0; 210 | padding:10px 0 0 0; 211 | background-color: #fff; 212 | } 213 | 214 | #qunit-tests li ol li { 215 | list-style-position: inside; 216 | list-style-type:decimal; 217 | *list-style-position: outside; 218 | } 219 | 220 | #qunit-tests table { 221 | border-collapse: collapse; 222 | margin-top: .2em; 223 | } 224 | 225 | #qunit-tests th { 226 | text-align: right; 227 | vertical-align: top; 228 | padding: 0 .5em 0 0; 229 | } 230 | 231 | #qunit-tests td { 232 | vertical-align: top; 233 | } 234 | 235 | #qunit-tests pre { 236 | margin: 0; 237 | white-space: pre-wrap; 238 | word-wrap: break-word; 239 | } 240 | 241 | #qunit-tests del { 242 | background-color: #add566; 243 | color: #555; 244 | text-decoration: none; 245 | } 246 | 247 | #qunit-tests ins { 248 | background-color: #f5857c; 249 | color: #555; 250 | text-decoration: none; 251 | } 252 | 253 | /*** Test Counts */ 254 | 255 | #qunit-tests b.counts { 256 | color: #7B7979; 257 | font-size:0.8em; 258 | margin-left:10px; 259 | } 260 | 261 | b.counts b.passed, b.counts b.failed { 262 | display:inline-block; 263 | padding:0px 1px; 264 | border-radius: 3px; 265 | -moz-border-radius: 3px; 266 | -webkit-border-radius: 3px; 267 | color:#FFF; 268 | } 269 | 270 | b.counts b.passed { 271 | background:#76b900; 272 | } 273 | 274 | b.counts b.failed { 275 | background:#ee3324; 276 | } 277 | 278 | 279 | #qunit-tests li li { 280 | margin:0 0 5px; 281 | padding: 0.4em 0.5em 0.4em 0.5em; 282 | background-color: #fff; 283 | border-bottom: none; 284 | border-radius: 3px; 285 | -moz-border-radius: 3px; 286 | -webkit-border-radius: 3px; 287 | overflow:auto; 288 | } 289 | 290 | /*** Passing Styles */ 291 | 292 | #qunit-tests li li.pass { 293 | color: #7B7979; 294 | background-color: #fff; 295 | border-left: 20px solid #76B900; 296 | } 297 | 298 | #qunit-tests .pass { color: #76B900; background-color: #FFF; border: 1px solid #add566; } 299 | 300 | #qunit-tests .pass .test-actual, 301 | #qunit-tests .pass .test-expected { color: #999999; } 302 | 303 | 304 | /*** Failing Styles */ 305 | #qunit-tests li.fail ol { 306 | background:#f7f7f7; 307 | } 308 | 309 | #qunit-tests li li.fail { 310 | color: #7B7979; 311 | background-color: #fff; 312 | border-left: 20px solid #EE3324; 313 | white-space: pre; 314 | } 315 | 316 | #qunit-tests .fail { color: #EE3324; border: 1px solid #f5857c; background-color: #f7f7f7; } 317 | 318 | 319 | #qunit-tests .fail .test-actual, 320 | #qunit-tests .fail .test-expected { color: #999999; } 321 | 322 | 323 | 324 | /** Result */ 325 | 326 | p#qunit-testresult { 327 | padding: 10px 0; 328 | font-weight:bold; 329 | line-height:1.6em; 330 | color: #7B7979; 331 | } 332 | 333 | p#qunit-testresult span.passed, p#qunit-testresult span.failed { 334 | font-size:1.5em; 335 | font-weight:bold; 336 | display:inline-block; 337 | padding:3px; 338 | border-radius: 5px; 339 | -moz-border-radius: 5px; 340 | -webkit-border-radius: 5px; 341 | } 342 | 343 | p#qunit-testresult span.passed { 344 | color:#FFF; 345 | background:#76b900 346 | } 347 | 348 | p#qunit-testresult span.failed { 349 | color:#FFF; 350 | background:#ee3324; 351 | } 352 | 353 | 354 | /** Fixture */ 355 | 356 | #qunit-fixture { 357 | position: absolute; 358 | top: -10000px; 359 | left: -10000px; 360 | width: 1000px; 361 | height: 1000px; 362 | } 363 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 1.10.0 / 2012-08-30 2 | ================== 3 | 4 | * Simplify licensing: Only MIT, no more MIT/GPL dual licensing. 5 | * Scroll the window back to top after tests finished running. Fixes #304 6 | * Simplify phantomjs runner to use module property in testDone callback 7 | * Adds module and test name to the information that is returned in the callback provided to QUnit.log(Function). Fixes #296 8 | * Make QUnit.expect() (without arguments) a getter. Fixes #226 9 | * Compare the ES6 sticky (y) property for RegExp. Can't add to tests yet. Fixes #284 - deepEqual for RegExp should compare 10 | * onerror: force display of global errors despite URL parameters. Fixes #288 - Global failures can be filtered out by test-limiting URL parameters 11 | * Remove conditional codepath based on jQuery presence from reset(). 12 | * Add module filter to UI 13 | * Keep a local reference to Date. Fixes #283. 14 | * Update copyright to jQuery Foundation. 15 | 16 | 1.9.0 / 2012-07-11 17 | ================== 18 | * added jsdoc for QUnit.assert functions 19 | * Styling: radius to 5px and small pass/error border, remove inner shadow 20 | * Move checkboxes into toolbar and give them labels and descriptions (as tooltip). Fixes #274 - Improve urlFilter API and UI 21 | * Where we recieve no exception in throws() use a relevant message. 22 | * Also make module filter case-insensitive. Follow-up to #252 23 | * Banner: Link should ignore "testNumber" and "module". Fixes #270 24 | * Rename assert.raises to assert.throws. Fixes #267 25 | * Change package.json name property to 'qunitjs' to avoid conflicht with node-qunit; will publish next release to npm 26 | 27 | 1.8.0 / 2012-06-14 28 | ================== 29 | * Improve window.onerror handling 30 | * (issue #260) config.current should be reset at the right time. 31 | * Filter: Implement 'module' url parameter. Fixes #252 32 | * raises: ignore global exceptions stemming from test. Fixes #257 - Globally-executed errors sneak past raises in IE 33 | 34 | 1.7.0 / 2012-06-07 35 | ================== 36 | 37 | * Add config.requireExpects. Fixes #207 - Add option to require all tests to call expect(). 38 | * Improve extractStacktrace() implementation. Fixes #254 - Include all relevant stack lines 39 | * Make filters case-insensitive. Partial fix for #252 40 | * is() expects lowercase types. Fixes #250 - Expected Date value is not displayed properly 41 | * Fix phantomjs addon header and add readme. Fixes #239 42 | * Add some hints to composite addon readme. Fixes #251 43 | * Track tests by the order in which they were run and create rerun links based on that number. Fixes #241 - Make Rerun link run only a single test. 44 | * Use QUnit.push for raises implementation. Fixes #243 45 | * CLI runner for phantomjs 46 | * Fix jshint validation until they deal with /** */ comments properly 47 | * Update validTest() : Simplify logic, clarify vars and add comments 48 | * Refactor assertion helpers into QUnit.assert (backwards compatible) 49 | * Add Rerun link to placeholders. Fixes #240 50 | 51 | 1.6.0 / 2012-05-04 52 | ================== 53 | 54 | * Save stack for each test, use that for failed expect() results, points at the line where test() was called. Fixes #209 55 | * Prefix test-output id and ignore that in noglobals check. Fixes #212 56 | * Only check for an exports object to detect a CommonJS enviroment. Fixes #237 - Incompatibility with require.js 57 | * Add testswarm integration as grunt task 58 | * Added padding on URL config checkboxes. 59 | * Cleanup composite addon: Use callback registration instead of overwriting them. Set the correct src on rerun link (and dblclick). Remove the composite test itself, as that was a crazy hack not worth maintaining 60 | * Cleanup reset() test and usage - run testDone callback first, to allow listeneres ignoring reset assertions 61 | * Double clicking on composite test rows opens individual test page 62 | * test-message for all message-bearing API reporting details 63 | 64 | 1.5.0 / 2012-04-04 65 | ================== 66 | 67 | * Modify "Running..." to display test name. Fixes #220 68 | * Fixed clearing of sessionStorage in Firefox 3.6. 69 | * Fixes #217 by calling "block" with config.current.testEnvironment 70 | * Add stats results to data. QUnit.jUnitReport function take one argument { xml:' QUnit.start() 143 | * Remove the 'let teardown clean up globals test' - IE<9 doesn't support (==buggy) deleting window properties, and that's not worth the trouble, as everything else passes just fine. Fixes #155 144 | * Fix globals in test.js, part 2 145 | * Fix globals in test.js. ?tell wwalser to use ?noglobals everyonce in a while 146 | * Extend readme regarding release process 147 | 148 | 1.1.0 / 2011-10-11 149 | ================== 150 | 151 | * Fixes #134 - Add a window.onerror handler. Makes uncaught errors actually fail the testsuite, instead of going by unnoticed. 152 | * Whitespace cleanup 153 | * Merge remote branch 'trevorparscal/master' 154 | * Fixed IE compatibility issues with using toString on NodeList objects, which in some browsers results in [object Object] rather than [object NodeList]. Now using duck typing for NodeList objects based on the presence of length, length being a number, presence of item method (which will be typeof string in IE and function in others, so we just check that it's not undefined) and that item(0) returns the same value as [0], unless it's empty, in which case item(0) will return 0, while [0] would return undefined. Tested in IE6, IE8, Firefox 6, Safari 5 and Chrome 16. 155 | * Update readme with basic notes on releases 156 | * More whitespace/parens cleanup 157 | * Check if setTimeout is available before trying to delay running the next task. Fixes #160 158 | * Whitespace/formatting fix, remove unnecessary parens 159 | * Use alias for Object.prototype.toString 160 | * Merge remote branch 'trevorparscal/master' 161 | * Merge remote branch 'wwalser/recursionBug' 162 | * Default 'expected' to null in asyncTest(), same as in test() itself. 163 | * Whitespace cleanup 164 | * Merge remote branch 'mmchaney/master' 165 | * Merge remote branch 'Krinkle/master' 166 | * Using === instead of == 167 | * Added more strict array type detection for dump output, and allowed NodeList objects to be output as arrays 168 | * Fixes a bug where after an async test, assertions could move between test cases because of internal state (config.current) being incorrectly set 169 | * Simplified check for assertion count and adjusted whitespace 170 | * Redo of fixing issue #156 (Support Object.prototype extending environment). * QUnit.diff: Throws exception without this if Object.prototype is set (Property 'length' of undefined. Since Object.prototype.foo doesn't have a property 'rows') * QUnit.url: Without this fix, if Object.prototype.foo is set, the url will be set to ?foo=...&the=rest. * saveGlobals: Without this fix, whenever a member is added to Object.prototype, saveGlobals will think it was a global variable in this loop. --- This time using the call method instead of obj.hasOwnProperty(key), which may fail if the object has that as it's own property (touché!). 171 | * Handle expect(0) as expected, i.e. expect(0); ok(true, foo); will cause a test to fail 172 | 173 | 1.0.0 / 2011-10-06 174 | ================== 175 | 176 | * Make QUnit work with TestSwarm 177 | * Run other addons tests as composite addon demo. Need to move that to /test folder once this setup actually works 178 | * Add-on: New assertion-type: step() 179 | * added parameter to start and stop allowing a user to increment/decrement the semaphore more than once per call 180 | * Update readmes with .md extension for GitHub to render them as markdown 181 | * Update close-enough addon to include readme and match (new) naming convetions 182 | * Merge remote branch 'righi/close-enough-addon' 183 | * Canvas addon: Update file referneces 184 | * Update canvas addon: Rename files and add README 185 | * Merge remote branch 'wwalser/composite' 186 | * Fix #142 - Backslash characters in messages should not be escaped 187 | * Add module name to testStart and testDone callbacks 188 | * Removed extra columns in object literals. Closes #153 189 | * Remove dead links in comments. 190 | * Merge remote branch 'wwalser/multipleCallbacks' 191 | * Fixed syntax error and CommonJS incompatibilities in package.json 192 | * Allow multiple callbacks to be registered. 193 | * Add placeholder for when Safari may end up providing useful error handling 194 | * changed file names to match addon naming convention 195 | * Whitespace 196 | * Created the composite addon. 197 | * Using array and object literals. 198 | * Issue #140: Make toggle system configurable. 199 | * Merge remote branch 'tweetdeck/master' 200 | * Adds the 'close enough' addon to determine if numbers are acceptably close enough in value. 201 | * Fix recursion support in jsDump, along with tests. Fixes #63 and #100 202 | * Adding a QUnit.config.altertitle flag which will allow users to opt-out of the functionality introduced in 60147ca0164e3d810b8a9bf46981c3d9cc569efc 203 | * Refactor window.load handler into QUnit.load, makes it possible to call it manually. 204 | * More whitespace cleanup 205 | * Merge remote branch 'erikvold/one-chk-in-title' 206 | * Whitespace 207 | * Merge remote branch 'wwalser/syncStopCalls' 208 | * Introducing the first QUnit addon, based on https://github.com/jquery/qunit/pull/84 - adds QUnit.pixelEqual assertion method, along with example tests. 209 | * Remove config.hidepassed setting in test.js, wasn't intended to land in master. 210 | * Expose QUnit.config.hidepassed setting. Overrides sessionStorage and enables enabling the feature programmatically. Fixes #133 211 | * Fix formatting (css whitespace) for tracebacks. 212 | * Expose extend, id, and addEvent methods. 213 | * minor comment typo correction 214 | * Ignore Eclipse WTP .settings 215 | * Set 'The jQuery Project' as author in package.json 216 | * Fixes a bug where synchronous calls to stop would cause tests to end before start was called again 217 | * Point to planning testing wiki in readme 218 | * only add one checkmark to the document.title 219 | * Escape the stacktrace output before setting it as innerHTML, since it tends to contain `<` and `>` characters. 220 | * Cleanup whitespace 221 | * Run module.teardown before checking for pollution. Fixes #109 - noglobals should run after module teardown 222 | * Fix accidental global variable "not" 223 | * Update document.title status to use more robust unicode escape sequences, works even when served with non-utf-8-charset. 224 | * Modify document.title when suite is done to show success/failure in tab, allows you to see the overall result without seeing the tab content. 225 | * Merge pull request #107 from sexyprout/master 226 | * Set a generic font 227 | * Add/update headers 228 | * Drop support for deprecated #main in favor of #qunit-fixture. If this breaks your testsuite, replace id="main" with id="qunit-fixture". Fixes #103 229 | * Remove the same key as the one being set. Partial fix for #101 230 | * Don't modify expected-count when checking pollution. The failing assertion isn't expected, so shouldn't be counted. And if expect wasn't used, the count is misleading. 231 | * Fix order of noglobals check to produce correct introduced/delete error messages 232 | * Prepend module name to sessionStorage keys to avoid conflicts 233 | * Store filter-tests only when checked 234 | * Write to sessionStorage only bad tests 235 | * Moved QUnit.url() defintion after QUnit properties are merged into the global scope. Fixes #93 - QUnit url/extend function breaking urls in jQuery ajax test component 236 | * Add a "Rerun" link to each test to replce the dblclick (still supported, for now). 237 | * Fixed the regex for parsing the name of a test when double clicking to filter. 238 | * Merge remote branch 'scottgonzalez/url' 239 | * Added checkboxes to show which flags are currently on and allow toggling them. 240 | * Retain all querystring parameters when filtering a test via double click. 241 | * Added better querystring parsing. Now storing all querystring params in QUnit.urlParams so that we can carry the params forward when filtering to a specific test. This removes the ability to specify multiple filters. 242 | * Make reordering optional (QUnit.config.reorder = false) and optimize "Hide passed tests" mode by also hiding "Running [testname]" entries. 243 | * Added missing semicolons and wrapped undefined key in quotes. 244 | * Optimize test hiding, add class on page load if stored in sessionStorage 245 | * Optimize the hiding of passed tests. 246 | * Position test results above test list, making it visible without ever having to scroll. Create a placeholder to avoid pushing down results later. 247 | * Don't check for existing qunit-testresult element, it gets killed on init anyway. 248 | * Added URL flag ?notrycatch (ala ?noglobals) for debugging exceptions. Won't try/catch test code, giving better debugging changes on the original exceptions. Fixes #72 249 | * Always show quni-toolbar (if at all specified), persist checkbox via sessionStorage. Fixes #47 250 | * Use non-html testname for calls to fail(). Fixes #77 251 | * Overhaul of QUnit.callbacks. Consistent single argument with related properties, with additonal runtime property for QUnit.done 252 | * Extended test/logs.html to capture more of the callbacks. 253 | * Fixed moduleStart/Done callbacks. Added test/logs.html to test these callbacks. To be extended. 254 | * Update copyright and license header. Fixes #61 255 | * Formatting fix. 256 | * Use a semaphore to synchronize stop() and start() calls. Fixes #76 257 | * Merge branch 'master' of https://github.com/paulirish/qunit into paulirish-master 258 | * Added two tests for previous QUnit.raises behaviour. For #69 259 | * add optional 2. arg to QUnit.raises #69. 260 | * fix references inside Complex Instances Nesting to what was originally intended. 261 | * Qualify calls to ok() in raises() for compability with CLI enviroments. 262 | * Fix done() handling, check for blocking, not block property 263 | * Fix moduleStart/Done and done callbacks. 264 | * Replacing sessionStorage test with the one from Modernizr/master (instead of current release). Here's hoping it'll work for some time. 265 | * Updated test for availibility of sessionStorage, based on test from Modernizr. Fixes #64 266 | * Defer test execution when previous run passed, persisted via sessionStorage. Fixes #49 267 | * Refactored module handling and queuing to enable selective defer of test runs. 268 | * Move assertions property from config to Test 269 | * Move expected-tests property from config to Test 270 | * Refactored test() method to delegate to a Test object to encapsulate all properties and methods of a single test, allowing further modifications. 271 | * Adding output of sourcefile and linenumber of failed assertions (except ok()). Only limited cross-browser support for now. Fixes #60 272 | * Drop 'hide missing tests' feature. Fixes #48 273 | * Adding readme. Fixes #58 274 | * Merge branch 'prettydiff' 275 | * Improve jsDump output with formatted diffs. 276 | * Cleanup whitespace 277 | * Cleanup whitespace 278 | * Added additional guards around browser specific code and cleaned up jsDump code 279 | * Added guards around tests which are only for browsers 280 | * cleaned up setTimeout undefined checking and double done on test finish 281 | * fixing .gitignore 282 | * making window setTimeout query more consistent 283 | * Moved expect-code back to beginning of function, where it belongs. Fixes #52 284 | * Bread crumb in header: Link to suite without filters, add link to current page based on the filter, if present. Fixes #50 285 | * Make the toolbar element optional when checking for show/hide of test results. Fixes #46 286 | * Adding headless.html to manually test logging and verify that QUnit works without output elements. Keeping #qunit-fixture as a few tests actually use that. 287 | * Fix for QUnit.moduleDone, get rid of initial bogus log. Fixes #33 288 | * Pass raw data (result, message, actual, expected) as third argument to QUnit.log. Fixes #32 289 | * Dump full exception. Not pretty, but functional (see issue Pretty diff for pretty output). Fixes #31 290 | * Don't let QUnit.reset() cause assertions to run. Manually applied from Scott Gonzalez branch. Fixes #34 291 | * Added missing semicolons. Fixes #37 292 | * Show okay/failed instead of undefined. Fixes #38 293 | * Expose push as QUnit.push to build custom assertions. Fixes #39 294 | * Respect filter pass selection when writing new results. Fixes #43 295 | * Cleanup tests, removing asyncTest-undefined check and formatting 296 | * Reset: Fall back to innerHTML when jQuery isn't available. Fixes #44 297 | * Merge branch 'master' of github.com:jquery/qunit 298 | * reset doesn't exist here - fixes #28. 299 | * - less css cruft, better readability - replaced inline style for test counts with "counts" class - test counts now use a "failed"/"passed" vs "pass"/"fail", shorter/more distinct selectors - pulled all test counts styling together and up (they're always the same regardless of section pass/fail state) 300 | * Adding .gitignore file 301 | * Removing diff test - diffing works fine, as the browser collapses whitespace in its output, but the test can't do that and isn't worth fixing. 302 | * Always synchronize the done-step (it'll set the timeout when necessary), fixes timing race conditions. 303 | * Insert location.href as an anchor around the header. Fixes issue #29 304 | * - kill double ;; in escapeHtml. oops 305 | * Removed html escaping from QUnit.diff, as input is already escaped, only leads to double escaping. Replaced newlines with single whitespace. 306 | * Optimized and cleaned up CSS file 307 | * Making the reset-method non-global (only module, test and assertions should be global), and fixing the fixture reset by using jQuery's html() method again, doesn't work with innerHTML, yet 308 | * Introducing #qunit-fixture element, deprecating the (never documented) #main element. Doesn't require inline styles and is now independent of jQuery. 309 | * Ammending previous commit: Remove jQuery-core specific resets (will be replaced within jQuery testsuite). Fixes issue #19 - QUnit.reset() removes global jQuery ajax event handlers 310 | * Remove jQuery-core specific resets (will be replaced within jQuery testsuite). Fixes issue #19 - QUnit.reset() removes global jQuery ajax event handlers 311 | * Cleaning up rubble from the previous commit. 312 | * Added raises assertion, reusing some of kennsnyder's code. 313 | * Merged kensnyder's object detection code. Original message: Streamlined object detection and exposed QUnit.objectType as a function. 314 | * Fixed some bad formatting. 315 | * Move various QUnit properties below the globals-export to avoid init becoming a global method. Fixes issue #11 - Remove 'init' function from a global namespace 316 | * Improved output when expected != actual: Output both only then, and add a diff. Fixes issue #10 - Show diff if equal() or deepEqual() failed 317 | * Expand failed tests on load. Fixes issue #8 - Failed tests expanded on load 318 | * Set location.search for url-filtering instead of location.href. Fixes issue #7 - Modify location.search instead of location.href on test double-click 319 | * Add QUnit.begin() callback. Fixes issue #6 - Add 'start' callback. 320 | * add css style for result (".test-actual") in passed tests 321 | * Fixed output escaping by using leeoniya's custom escaping along with innerHTML. Also paves the way for outputting diffs. 322 | * Cleanup 323 | * Revert "Revert part of bad merge, back to using createTextNode" 324 | * Revert part of bad merge, back to using createTextNode 325 | * Fixed doubleclick-handler and filtering to rerun only a single test. 326 | * Add ability to css style a test's messages, expected and actual results. Merged from Leon Sorokin (leeoniya). 327 | * Remove space between module name and colon 328 | * - removed "module" wording from reports (unneeded and cluttery) - added and modified css to make module & test names styleable 329 | * Logging support for Each test can extend the module testEnvironment 330 | * Fixing whitespace 331 | * Update tests to use equal() and deepEqual() rather than the deprecated equals() and same() 332 | * Consistent argument names for deepEqual 333 | * Skip DOM part of jsDump test if using a SSJS environment without a DOM 334 | * Improve async testing by creating the result element before running the test, updating it later. If the test fails, its clear which test is the culprit. 335 | * Add autostart option to config. Set via QUnit.config.autostart = false; start later via QUnit.start() 336 | * Expose QUnit.config, but don't make config a global 337 | * Expose QUnit.config as global to make external workarounds easier 338 | * Merge branch 'asyncsetup' 339 | * Allowing async setup and teardown. Fixes http://github.com/jquery/qunit/issues#issue/20 340 | * Always output expected and actual result (no reason not to). Fixes http://github.com/jquery/qunit/issues#issue/21 341 | * More changes to the detection of types in jsDump's typeOf. 342 | * Change the typeOf checks in QUnit to be more accurate. 343 | * Added test for jsDump and modified its options to properly output results when document.createTextNode is used; currently tests for DOM elements cause a stackoverflow error in IEs, works fine, with the correct output, elsewhere 344 | * Always use jsDump to output result objects into messages, making the output for passing assertions more useful 345 | * Make it so that the display is updated, at least, once a second - also prevents scripts from executing for too long and causing problems. 346 | * added tests and patch for qunit.equiv to avoid circular references in objects and arrays 347 | * No reason to continue looping, we can stop at this point. Thanks to Chris Thatcher for the suggestion. 348 | * Use createTextNode instead of innerHTML for showing test result since expected and actual might be something that looks like a tag. 349 | * 'Test card' design added 350 | * switched green to blue for top-level pass + reduced padding 351 | * Bringing the QUnit API in line with the CommonJS API. 352 | * Explicitly set list-style-position: inside on result LIs. 353 | * Madness with border-radius. 354 | * Corrected banner styles for new class names 355 | * Added rounded corners and removed body rules for embedded tests 356 | * Resolving merge conflicts. 357 | * added colouring for value summary 358 | * adding some extra text colours 359 | * added styles for toolbar 360 | * added new styles 361 | * IE 6 and 7 weren't respecting the CSS rules for the banner, used a different technique instead. 362 | * Went a bit further and made extra-sure that the target was specified correctly. 363 | * Fixed problem where double-clicking an entry in IE caused an error to occur. 364 | * Path for http://dev.jquery.com/ticket/5426 - fix the microformat test result 365 | * Fixed test() to use 'expected' 2nd param 366 | * Remove the named function expressions, to stop Safari 2 from freaking out. Fixes #5. 367 | * Each test can extend the module testEnvironment 368 | * Extra test for current test environment 369 | * Make the current testEnvironment available to utility functions 370 | * typeOf in QUnit.jsDump now uses QUnit.is 371 | * hoozit in QUnit.equiv now uses QUnit.is 372 | * Properly set label attributes. 373 | * Some minor tweaks to RyanS' GETParams change. 374 | * left a console.log in :( 375 | * Took into account a fringe case when using qunit with testswarm. Trying to run all the tests with the extra url params from testswarm would make qunit look for a testsuite that did not exist 376 | * need to set config.currentModule to have correct names and working filters 377 | * Support logging of testEnvironment 378 | * async tests aren't possible on rhino 379 | * Fixed a missing QUnit.reset(). 380 | * The QUnit. prefix was missing from the uses of the start() method. 381 | * Merged lifecycle object into testEnvironment 382 | * "replacing totally wrong diff algorithm with a working one" Patch from kassens (manually applied). 383 | * fixing jslint errors in test.js 384 | * Fixed: testDone() was always called with 0 failures in CommonJS mode 385 | * Fixed: moduleDone() was invoked on first call to module() 386 | * Added a new asyncTest method - removes the need for having to call start() at the beginning of an asynchronous test. 387 | * Added support for expected numbers in the test method. 388 | * Fixed broken dynamic loading of tests (can now dynamically load tests and done still works properly). 389 | * Simplified the logic for calling 'done' and pushing off new tests - was causing too many inconsistencies otherwise. 390 | * Simplified the markup for the QUnit test test suite. 391 | * Realized that it's really easy to handle the case where stop() has been called and then an exception is thrown. 392 | * Added in better logging support. Now handle moduleStart/moduleDone and testStart/testDone. Also make sure that done only fires once at the end. 393 | * Made it so that you can reset the suite to an initial state (at which point tests can be dynamically loaded and run, for example). 394 | * Re-worked QUnit to handle dynamic loading of additional code (the 'done' code will be re-run after additional code is loaded). 395 | * Removed the old SVN version stuff. 396 | * Moved the QUnit source into a separate directory and updated the test suite/packages files. 397 | * Added in CommonJS support for exporting the QUnit functionality. 398 | * Missing quote from package.json. 399 | * Fixed trailing comma in package.json. 400 | * Added a CommonJS/Narwhal package.json file. 401 | * Accidentally reverted the jsDump/equiv changes that had been made. 402 | * Hide the filter toolbar if it's not needed. Also exposed the jsDump and equiv objects on QUnit. 403 | * Retooled the QUnit CSS to be more generic. 404 | * Renamed the QUnit files from testrunner/testsuite to QUnit. 405 | * Expose QUnit.equiv and QUnit.jsDump in QUnit. 406 | * Moved the QUnit test directory into the QUnit directory. 407 | * Reworked the QUnit CSS (moved jQuery-specific stuff out, made all the other selectors more specific). 408 | * Removed the #main reset for non-jQuery code (QUnit.reset can be overwritten with your own reset code). 409 | * Moved the QUnit toolbar inline. 410 | * Switched to using a qunit- prefix for special elements (banner, userAgent, and tests). 411 | * Missed a case in QUnit where an element was assumed to exist. 412 | * QUnit's isSet and isObj are no longer needed - you should use same instead. 413 | * Make sure that QUnit's equiv entity escaping is enabled by default (otherwise the output gets kind of crazy). 414 | * Refactored QUnit, completely reorganized the structure of the file. Additionally made it so that QUnit can run outside of a browser (inside Rhino, for example). 415 | * Removed some legacy and jQuery-specific test methods. 416 | * Added callbacks for tests and modules. It's now possible to reproduce the full display of the testrunner without using the regular rendering. 417 | * QUnit no longer depends upon rendering the results (it can work simply by using the logging callbacks). 418 | * Made QUnit no longer require jQuery (it is now a standalone, framework independent, test runner). 419 | * Reverted the noglobals changed from QUnit - causing chaos in the jQuery test suite. 420 | * qunit: removed noglobals flag, instead always check for globals after teardown; if a test has to introduce a global "myVar", use delete window.myVar in teardown or at the end of a test 421 | * qunit: don't child selectors when IE should behave nicely, too 422 | * qunit: improvment for the test-scope: create a new object and call setup, the test, and teardown in the scope of that object - allows you to provide test fixtures to each test without messing with global data; kudos to Martin Häcker for the contribution 423 | * qunit: added missing semicolons 424 | * qunit: fixed a semicolon, that should have been a comma 425 | * QUnit: implemented error handling for Opera as proposed by #3628 426 | * qunit: fix for http://dev.jquery.com/ticket/3215 changing wording of testresults, to something more positive (x of y passed, z failed) 427 | * QUnit: testrunner.js: Ensures equality of types (String, Boolean, Number) declared with the 'new' prefix. See comments #3, #4 and #5 on http://philrathe.com/articles/equiv 428 | * qunit: wrap name of test in span when a module is used for better styling 429 | * qunit: auto-prepend default mark (#header, #banner, #userAgent, #tests) when not present 430 | * Landing some changes to add logging to QUnit (so that it's easier to hook in to when a test finishes). 431 | * Added checkbox for hiding missing tests (tests that fail with the text 'missing test - untested code is broken code') 432 | * qunit: eol-style:native and mime-type 433 | * HTML being injected for the test result wasn't valid HTML. 434 | * qunit: setting mimetype for testsuite.css 435 | * qunit: update to Ariel's noglobals patch to support async tests as well 436 | * Landing Ariel's change - checks for global variable leakage. 437 | * qunit: run module-teardown in its own synchronize block to synchronize with async tests (ugh) 438 | * qunit: same: equiv - completely refactored in the testrunner. 439 | * testrunner.js: - Update equiv to support Date and RegExp. - Change behavior when comparing function: - abort when in an instance of Object (when references comparison failed) - skip otherwise (like before) 440 | * qunit: code refactoring and cleanup 441 | * QUnit: update equiv to latest version, handling multiple arguments and NaN, see http://philrathe.com/articles/equiv 442 | * QUnit: cleanup, deprecating compare, compare2 and serialArray: usage now throws an error with a helpful message 443 | * QUnit: optional timeout argument for stop, while making tests undetermined, useful for debugging 444 | * QUnit: added toolbar with "hide passed tests" checkbox to help focus on failed tests 445 | * QUnit: minor output formatting 446 | * QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests 447 | * QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests 448 | * QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests 449 | * qunit: use window.load to initialize tests, allowing other code to run on document-ready before starting to run tests 450 | * qunit: allow either setup or teardown, instead of both or nothing 451 | * qunit: make everything private by default, expose only public API; removed old timeout-option (non-deterministic, disabled for a long time anyway); use local $ reference instead of global jQuery reference; minor code cleanup (var config instead of _config; queue.shift instead of slice) 452 | * qunit: added support for module level setup/teardown callbacks 453 | * qunit: modified example for equals to avoid confusion with parameter ordering 454 | * qunit: added id/classes to result element to enable integration with browser automation tools, see http://docs.jquery.com/QUnit#Integration_into_Browser_Automation_Tools 455 | * qunit: replaced $ alias with jQuery (merged from jquery/test/data/testrunner.js) 456 | * qunit: fixed inline documentation for equals 457 | * qunit testrunner - catch and log possible error during reset() 458 | * QUnit: Switched out Date and Rev for Id. 459 | * qunit: when errors are thrown in a test, the message is successfully show on all browsers. 460 | * qunit: added license header 461 | * qunit: moved jquery testrunner to top-level project, see http://docs.jquery.com/QUnit 462 | * Share project 'qunit' into 'https://jqueryjs.googlecode.com/svn' 463 | -------------------------------------------------------------------------------- /test/deepEqual.js: -------------------------------------------------------------------------------- 1 | module("equiv"); 2 | 3 | 4 | test("Primitive types and constants", function () { 5 | equal(QUnit.equiv(null, null), true, "null"); 6 | equal(QUnit.equiv(null, {}), false, "null"); 7 | equal(QUnit.equiv(null, undefined), false, "null"); 8 | equal(QUnit.equiv(null, 0), false, "null"); 9 | equal(QUnit.equiv(null, false), false, "null"); 10 | equal(QUnit.equiv(null, ''), false, "null"); 11 | equal(QUnit.equiv(null, []), false, "null"); 12 | 13 | equal(QUnit.equiv(undefined, undefined), true, "undefined"); 14 | equal(QUnit.equiv(undefined, null), false, "undefined"); 15 | equal(QUnit.equiv(undefined, 0), false, "undefined"); 16 | equal(QUnit.equiv(undefined, false), false, "undefined"); 17 | equal(QUnit.equiv(undefined, {}), false, "undefined"); 18 | equal(QUnit.equiv(undefined, []), false, "undefined"); 19 | equal(QUnit.equiv(undefined, ""), false, "undefined"); 20 | 21 | // Nan usually doest not equal to Nan using the '==' operator. 22 | // Only isNaN() is able to do it. 23 | equal(QUnit.equiv(0/0, 0/0), true, "NaN"); // NaN VS NaN 24 | equal(QUnit.equiv(1/0, 2/0), true, "Infinity"); // Infinity VS Infinity 25 | equal(QUnit.equiv(-1/0, 2/0), false, "-Infinity, Infinity"); // -Infinity VS Infinity 26 | equal(QUnit.equiv(-1/0, -2/0), true, "-Infinity, -Infinity"); // -Infinity VS -Infinity 27 | equal(QUnit.equiv(0/0, 1/0), false, "NaN, Infinity"); // Nan VS Infinity 28 | equal(QUnit.equiv(1/0, 0/0), false, "NaN, Infinity"); // Nan VS Infinity 29 | equal(QUnit.equiv(0/0, null), false, "NaN"); 30 | equal(QUnit.equiv(0/0, undefined), false, "NaN"); 31 | equal(QUnit.equiv(0/0, 0), false, "NaN"); 32 | equal(QUnit.equiv(0/0, false), false, "NaN"); 33 | equal(QUnit.equiv(0/0, function () {}), false, "NaN"); 34 | equal(QUnit.equiv(1/0, null), false, "NaN, Infinity"); 35 | equal(QUnit.equiv(1/0, undefined), false, "NaN, Infinity"); 36 | equal(QUnit.equiv(1/0, 0), false, "NaN, Infinity"); 37 | equal(QUnit.equiv(1/0, 1), false, "NaN, Infinity"); 38 | equal(QUnit.equiv(1/0, false), false, "NaN, Infinity"); 39 | equal(QUnit.equiv(1/0, true), false, "NaN, Infinity"); 40 | equal(QUnit.equiv(1/0, function () {}), false, "NaN, Infinity"); 41 | 42 | equal(QUnit.equiv(0, 0), true, "number"); 43 | equal(QUnit.equiv(0, 1), false, "number"); 44 | equal(QUnit.equiv(1, 0), false, "number"); 45 | equal(QUnit.equiv(1, 1), true, "number"); 46 | equal(QUnit.equiv(1.1, 1.1), true, "number"); 47 | equal(QUnit.equiv(0.0000005, 0.0000005), true, "number"); 48 | equal(QUnit.equiv(0, ''), false, "number"); 49 | equal(QUnit.equiv(0, '0'), false, "number"); 50 | equal(QUnit.equiv(1, '1'), false, "number"); 51 | equal(QUnit.equiv(0, false), false, "number"); 52 | equal(QUnit.equiv(1, true), false, "number"); 53 | 54 | equal(QUnit.equiv(true, true), true, "boolean"); 55 | equal(QUnit.equiv(true, false), false, "boolean"); 56 | equal(QUnit.equiv(false, true), false, "boolean"); 57 | equal(QUnit.equiv(false, 0), false, "boolean"); 58 | equal(QUnit.equiv(false, null), false, "boolean"); 59 | equal(QUnit.equiv(false, undefined), false, "boolean"); 60 | equal(QUnit.equiv(true, 1), false, "boolean"); 61 | equal(QUnit.equiv(true, null), false, "boolean"); 62 | equal(QUnit.equiv(true, undefined), false, "boolean"); 63 | 64 | equal(QUnit.equiv('', ''), true, "string"); 65 | equal(QUnit.equiv('a', 'a'), true, "string"); 66 | equal(QUnit.equiv("foobar", "foobar"), true, "string"); 67 | equal(QUnit.equiv("foobar", "foo"), false, "string"); 68 | equal(QUnit.equiv('', 0), false, "string"); 69 | equal(QUnit.equiv('', false), false, "string"); 70 | equal(QUnit.equiv('', null), false, "string"); 71 | equal(QUnit.equiv('', undefined), false, "string"); 72 | 73 | // Short annotation VS new annotation 74 | equal(QUnit.equiv(0, new Number()), true, "short annotation VS new annotation"); 75 | equal(QUnit.equiv(new Number(), 0), true, "short annotation VS new annotation"); 76 | equal(QUnit.equiv(1, new Number(1)), true, "short annotation VS new annotation"); 77 | equal(QUnit.equiv(new Number(1), 1), true, "short annotation VS new annotation"); 78 | equal(QUnit.equiv(new Number(0), 1), false, "short annotation VS new annotation"); 79 | equal(QUnit.equiv(0, new Number(1)), false, "short annotation VS new annotation"); 80 | 81 | equal(QUnit.equiv(new String(), ""), true, "short annotation VS new annotation"); 82 | equal(QUnit.equiv("", new String()), true, "short annotation VS new annotation"); 83 | equal(QUnit.equiv(new String("My String"), "My String"), true, "short annotation VS new annotation"); 84 | equal(QUnit.equiv("My String", new String("My String")), true, "short annotation VS new annotation"); 85 | equal(QUnit.equiv("Bad String", new String("My String")), false, "short annotation VS new annotation"); 86 | equal(QUnit.equiv(new String("Bad String"), "My String"), false, "short annotation VS new annotation"); 87 | 88 | equal(QUnit.equiv(false, new Boolean()), true, "short annotation VS new annotation"); 89 | equal(QUnit.equiv(new Boolean(), false), true, "short annotation VS new annotation"); 90 | equal(QUnit.equiv(true, new Boolean(true)), true, "short annotation VS new annotation"); 91 | equal(QUnit.equiv(new Boolean(true), true), true, "short annotation VS new annotation"); 92 | equal(QUnit.equiv(true, new Boolean(1)), true, "short annotation VS new annotation"); 93 | equal(QUnit.equiv(false, new Boolean(false)), true, "short annotation VS new annotation"); 94 | equal(QUnit.equiv(new Boolean(false), false), true, "short annotation VS new annotation"); 95 | equal(QUnit.equiv(false, new Boolean(0)), true, "short annotation VS new annotation"); 96 | equal(QUnit.equiv(true, new Boolean(false)), false, "short annotation VS new annotation"); 97 | equal(QUnit.equiv(new Boolean(false), true), false, "short annotation VS new annotation"); 98 | 99 | equal(QUnit.equiv(new Object(), {}), true, "short annotation VS new annotation"); 100 | equal(QUnit.equiv({}, new Object()), true, "short annotation VS new annotation"); 101 | equal(QUnit.equiv(new Object(), {a:1}), false, "short annotation VS new annotation"); 102 | equal(QUnit.equiv({a:1}, new Object()), false, "short annotation VS new annotation"); 103 | equal(QUnit.equiv({a:undefined}, new Object()), false, "short annotation VS new annotation"); 104 | equal(QUnit.equiv(new Object(), {a:undefined}), false, "short annotation VS new annotation"); 105 | }); 106 | 107 | test("Objects Basics.", function() { 108 | equal(QUnit.equiv({}, {}), true); 109 | equal(QUnit.equiv({}, null), false); 110 | equal(QUnit.equiv({}, undefined), false); 111 | equal(QUnit.equiv({}, 0), false); 112 | equal(QUnit.equiv({}, false), false); 113 | 114 | // This test is a hard one, it is very important 115 | // REASONS: 116 | // 1) They are of the same type "object" 117 | // 2) [] instanceof Object is true 118 | // 3) Their properties are the same (doesn't exists) 119 | equal(QUnit.equiv({}, []), false); 120 | 121 | equal(QUnit.equiv({a:1}, {a:1}), true); 122 | equal(QUnit.equiv({a:1}, {a:"1"}), false); 123 | equal(QUnit.equiv({a:[]}, {a:[]}), true); 124 | equal(QUnit.equiv({a:{}}, {a:null}), false); 125 | equal(QUnit.equiv({a:1}, {}), false); 126 | equal(QUnit.equiv({}, {a:1}), false); 127 | 128 | // Hard ones 129 | equal(QUnit.equiv({a:undefined}, {}), false); 130 | equal(QUnit.equiv({}, {a:undefined}), false); 131 | equal(QUnit.equiv( 132 | { 133 | a: [{ bar: undefined }] 134 | }, 135 | { 136 | a: [{ bat: undefined }] 137 | } 138 | ), false); 139 | 140 | // Objects with no prototype, created via Object.create(null), are used e.g. as dictionaries. 141 | // Being able to test equivalence against object literals is quite useful. 142 | if (typeof Object.create === 'function') { 143 | equal(QUnit.equiv(Object.create(null), {}), true, "empty object without prototype VS empty object"); 144 | 145 | var nonEmptyWithNoProto = Object.create(null); 146 | nonEmptyWithNoProto.foo = "bar"; 147 | 148 | equal(QUnit.equiv(nonEmptyWithNoProto, { foo: "bar" }), true, "object without prototype VS object"); 149 | } 150 | }); 151 | 152 | 153 | test("Arrays Basics.", function() { 154 | 155 | equal(QUnit.equiv([], []), true); 156 | 157 | // May be a hard one, can invoke a crash at execution. 158 | // because their types are both "object" but null isn't 159 | // like a true object, it doesn't have any property at all. 160 | equal(QUnit.equiv([], null), false); 161 | 162 | equal(QUnit.equiv([], undefined), false); 163 | equal(QUnit.equiv([], false), false); 164 | equal(QUnit.equiv([], 0), false); 165 | equal(QUnit.equiv([], ""), false); 166 | 167 | // May be a hard one, but less hard 168 | // than {} with [] (note the order) 169 | equal(QUnit.equiv([], {}), false); 170 | 171 | equal(QUnit.equiv([null],[]), false); 172 | equal(QUnit.equiv([undefined],[]), false); 173 | equal(QUnit.equiv([],[null]), false); 174 | equal(QUnit.equiv([],[undefined]), false); 175 | equal(QUnit.equiv([null],[undefined]), false); 176 | equal(QUnit.equiv([[]],[[]]), true); 177 | equal(QUnit.equiv([[],[],[]],[[],[],[]]), true); 178 | equal(QUnit.equiv( 179 | [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], 180 | [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), 181 | true); 182 | equal(QUnit.equiv( 183 | [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], 184 | [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter 185 | false); 186 | equal(QUnit.equiv( 187 | [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], 188 | [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array 189 | false); 190 | 191 | // same multidimensional 192 | equal(QUnit.equiv( 193 | [1,2,3,4,5,6,7,8,9, [ 194 | 1,2,3,4,5,6,7,8,9, [ 195 | 1,2,3,4,5,[ 196 | [6,7,8,9, [ 197 | [ 198 | 1,2,3,4,[ 199 | 2,3,4,[ 200 | 1,2,[ 201 | 1,2,3,4,[ 202 | 1,2,3,4,5,6,7,8,9,[ 203 | 0 204 | ],1,2,3,4,5,6,7,8,9 205 | ],5,6,7,8,9 206 | ],4,5,6,7,8,9 207 | ],5,6,7,8,9 208 | ],5,6,7 209 | ] 210 | ] 211 | ] 212 | ] 213 | ]]], 214 | [1,2,3,4,5,6,7,8,9, [ 215 | 1,2,3,4,5,6,7,8,9, [ 216 | 1,2,3,4,5,[ 217 | [6,7,8,9, [ 218 | [ 219 | 1,2,3,4,[ 220 | 2,3,4,[ 221 | 1,2,[ 222 | 1,2,3,4,[ 223 | 1,2,3,4,5,6,7,8,9,[ 224 | 0 225 | ],1,2,3,4,5,6,7,8,9 226 | ],5,6,7,8,9 227 | ],4,5,6,7,8,9 228 | ],5,6,7,8,9 229 | ],5,6,7 230 | ] 231 | ] 232 | ] 233 | ] 234 | ]]]), 235 | true, "Multidimensional"); 236 | 237 | // different multidimensional 238 | equal(QUnit.equiv( 239 | [1,2,3,4,5,6,7,8,9, [ 240 | 1,2,3,4,5,6,7,8,9, [ 241 | 1,2,3,4,5,[ 242 | [6,7,8,9, [ 243 | [ 244 | 1,2,3,4,[ 245 | 2,3,4,[ 246 | 1,2,[ 247 | 1,2,3,4,[ 248 | 1,2,3,4,5,6,7,8,9,[ 249 | 0 250 | ],1,2,3,4,5,6,7,8,9 251 | ],5,6,7,8,9 252 | ],4,5,6,7,8,9 253 | ],5,6,7,8,9 254 | ],5,6,7 255 | ] 256 | ] 257 | ] 258 | ] 259 | ]]], 260 | [1,2,3,4,5,6,7,8,9, [ 261 | 1,2,3,4,5,6,7,8,9, [ 262 | 1,2,3,4,5,[ 263 | [6,7,8,9, [ 264 | [ 265 | 1,2,3,4,[ 266 | 2,3,4,[ 267 | 1,2,[ 268 | '1',2,3,4,[ // string instead of number 269 | 1,2,3,4,5,6,7,8,9,[ 270 | 0 271 | ],1,2,3,4,5,6,7,8,9 272 | ],5,6,7,8,9 273 | ],4,5,6,7,8,9 274 | ],5,6,7,8,9 275 | ],5,6,7 276 | ] 277 | ] 278 | ] 279 | ] 280 | ]]]), 281 | false, "Multidimensional"); 282 | 283 | // different multidimensional 284 | equal(QUnit.equiv( 285 | [1,2,3,4,5,6,7,8,9, [ 286 | 1,2,3,4,5,6,7,8,9, [ 287 | 1,2,3,4,5,[ 288 | [6,7,8,9, [ 289 | [ 290 | 1,2,3,4,[ 291 | 2,3,4,[ 292 | 1,2,[ 293 | 1,2,3,4,[ 294 | 1,2,3,4,5,6,7,8,9,[ 295 | 0 296 | ],1,2,3,4,5,6,7,8,9 297 | ],5,6,7,8,9 298 | ],4,5,6,7,8,9 299 | ],5,6,7,8,9 300 | ],5,6,7 301 | ] 302 | ] 303 | ] 304 | ] 305 | ]]], 306 | [1,2,3,4,5,6,7,8,9, [ 307 | 1,2,3,4,5,6,7,8,9, [ 308 | 1,2,3,4,5,[ 309 | [6,7,8,9, [ 310 | [ 311 | 1,2,3,4,[ 312 | 2,3,[ // missing an element (4) 313 | 1,2,[ 314 | 1,2,3,4,[ 315 | 1,2,3,4,5,6,7,8,9,[ 316 | 0 317 | ],1,2,3,4,5,6,7,8,9 318 | ],5,6,7,8,9 319 | ],4,5,6,7,8,9 320 | ],5,6,7,8,9 321 | ],5,6,7 322 | ] 323 | ] 324 | ] 325 | ] 326 | ]]]), 327 | false, "Multidimensional"); 328 | }); 329 | 330 | test("Functions.", function() { 331 | var f0 = function () {}; 332 | var f1 = function () {}; 333 | 334 | // f2 and f3 have the same code, formatted differently 335 | var f2 = function () {var i = 0;}; 336 | var f3 = function () { 337 | var i = 0 // this comment and no semicoma as difference 338 | }; 339 | 340 | equal(QUnit.equiv(function() {}, function() {}), false, "Anonymous functions"); // exact source code 341 | equal(QUnit.equiv(function() {}, function() {return true;}), false, "Anonymous functions"); 342 | 343 | equal(QUnit.equiv(f0, f0), true, "Function references"); // same references 344 | equal(QUnit.equiv(f0, f1), false, "Function references"); // exact source code, different references 345 | equal(QUnit.equiv(f2, f3), false, "Function references"); // equivalent source code, different references 346 | equal(QUnit.equiv(f1, f2), false, "Function references"); // different source code, different references 347 | equal(QUnit.equiv(function() {}, true), false); 348 | equal(QUnit.equiv(function() {}, undefined), false); 349 | equal(QUnit.equiv(function() {}, null), false); 350 | equal(QUnit.equiv(function() {}, {}), false); 351 | }); 352 | 353 | 354 | test("Date instances.", function() { 355 | // Date, we don't need to test Date.parse() because it returns a number. 356 | // Only test the Date instances by setting them a fix date. 357 | // The date use is midnight January 1, 1970 358 | 359 | var d1 = new Date(); 360 | d1.setTime(0); // fix the date 361 | 362 | var d2 = new Date(); 363 | d2.setTime(0); // fix the date 364 | 365 | var d3 = new Date(); // The very now 366 | 367 | // Anyway their types differs, just in case the code fails in the order in which it deals with date 368 | equal(QUnit.equiv(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different 369 | // test same values date and different instances equality 370 | equal(QUnit.equiv(d1, d2), true); 371 | // test different date and different instances difference 372 | equal(QUnit.equiv(d1, d3), false); 373 | }); 374 | 375 | 376 | test("RegExp.", function() { 377 | // Must test cases that imply those traps: 378 | // var a = /./; 379 | // a instanceof Object; // Oops 380 | // a instanceof RegExp; // Oops 381 | // typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object") 382 | 383 | // Tests same regex with same modifiers in different order 384 | var r = /foo/; 385 | var r5 = /foo/gim; 386 | var r6 = /foo/gmi; 387 | var r7 = /foo/igm; 388 | var r8 = /foo/img; 389 | var r9 = /foo/mig; 390 | var r10 = /foo/mgi; 391 | var ri1 = /foo/i; 392 | var ri2 = /foo/i; 393 | var rm1 = /foo/m; 394 | var rm2 = /foo/m; 395 | var rg1 = /foo/g; 396 | var rg2 = /foo/g; 397 | 398 | equal(QUnit.equiv(r5, r6), true, "Modifier order"); 399 | equal(QUnit.equiv(r5, r7), true, "Modifier order"); 400 | equal(QUnit.equiv(r5, r8), true, "Modifier order"); 401 | equal(QUnit.equiv(r5, r9), true, "Modifier order"); 402 | equal(QUnit.equiv(r5, r10), true, "Modifier order"); 403 | equal(QUnit.equiv(r, r5), false, "Modifier"); 404 | 405 | equal(QUnit.equiv(ri1, ri2), true, "Modifier"); 406 | equal(QUnit.equiv(r, ri1), false, "Modifier"); 407 | equal(QUnit.equiv(ri1, rm1), false, "Modifier"); 408 | equal(QUnit.equiv(r, rm1), false, "Modifier"); 409 | equal(QUnit.equiv(rm1, ri1), false, "Modifier"); 410 | equal(QUnit.equiv(rm1, rm2), true, "Modifier"); 411 | equal(QUnit.equiv(rg1, rm1), false, "Modifier"); 412 | equal(QUnit.equiv(rm1, rg1), false, "Modifier"); 413 | equal(QUnit.equiv(rg1, rg2), true, "Modifier"); 414 | 415 | // Different regex, same modifiers 416 | var r11 = /[a-z]/gi; 417 | var r13 = /[0-9]/gi; // oops! different 418 | equal(QUnit.equiv(r11, r13), false, "Regex pattern"); 419 | 420 | var r14 = /0/ig; 421 | var r15 = /"0"/ig; // oops! different 422 | equal(QUnit.equiv(r14, r15), false, "Regex pattern"); 423 | 424 | var r1 = /[\n\r\u2028\u2029]/g; 425 | var r2 = /[\n\r\u2028\u2029]/g; 426 | var r3 = /[\n\r\u2028\u2028]/g; // differs from r1 427 | var r4 = /[\n\r\u2028\u2029]/; // differs from r1 428 | 429 | equal(QUnit.equiv(r1, r2), true, "Regex pattern"); 430 | equal(QUnit.equiv(r1, r3), false, "Regex pattern"); 431 | equal(QUnit.equiv(r1, r4), false, "Regex pattern"); 432 | 433 | // More complex regex 434 | var regex1 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; 435 | var regex2 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; 436 | // regex 3 is different: '.' not escaped 437 | var regex3 = "^[-_.a-z0-9]+@([-_a-z0-9]+.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; 438 | 439 | var r21 = new RegExp(regex1); 440 | var r22 = new RegExp(regex2); 441 | var r23 = new RegExp(regex3); // diff from r21, not same pattern 442 | var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier 443 | var r24a = new RegExp(regex3, "ig"); // same as r23a 444 | 445 | equal(QUnit.equiv(r21, r22), true, "Complex Regex"); 446 | equal(QUnit.equiv(r21, r23), false, "Complex Regex"); 447 | equal(QUnit.equiv(r23, r23a), false, "Complex Regex"); 448 | equal(QUnit.equiv(r23a, r24a), true, "Complex Regex"); 449 | 450 | // typeof r1 is "function" in some browsers and "object" in others so we must cover this test 451 | var re = / /; 452 | equal(QUnit.equiv(re, function () {}), false, "Regex internal"); 453 | equal(QUnit.equiv(re, {}), false, "Regex internal"); 454 | }); 455 | 456 | 457 | test("Complex Objects.", function() { 458 | 459 | function fn1() { 460 | return "fn1"; 461 | } 462 | function fn2() { 463 | return "fn2"; 464 | } 465 | 466 | // Try to invert the order of some properties to make sure it is covered. 467 | // It can failed when properties are compared between unsorted arrays. 468 | equal(QUnit.equiv( 469 | { 470 | a: 1, 471 | b: null, 472 | c: [{}], 473 | d: { 474 | a: 3.14159, 475 | b: false, 476 | c: { 477 | e: fn1, 478 | f: [[[]]], 479 | g: { 480 | j: { 481 | k: { 482 | n: { 483 | r: "r", 484 | s: [1,2,3], 485 | t: undefined, 486 | u: 0, 487 | v: { 488 | w: { 489 | x: { 490 | y: "Yahoo!", 491 | z: null 492 | } 493 | } 494 | } 495 | }, 496 | q: [], 497 | p: 1/0, 498 | o: 99 499 | }, 500 | l: undefined, 501 | m: null 502 | } 503 | }, 504 | d: 0, 505 | i: true, 506 | h: "false" 507 | } 508 | }, 509 | e: undefined, 510 | g: "", 511 | h: "h", 512 | f: {}, 513 | i: [] 514 | }, 515 | { 516 | a: 1, 517 | b: null, 518 | c: [{}], 519 | d: { 520 | b: false, 521 | a: 3.14159, 522 | c: { 523 | d: 0, 524 | e: fn1, 525 | f: [[[]]], 526 | g: { 527 | j: { 528 | k: { 529 | n: { 530 | r: "r", 531 | t: undefined, 532 | u: 0, 533 | s: [1,2,3], 534 | v: { 535 | w: { 536 | x: { 537 | z: null, 538 | y: "Yahoo!" 539 | } 540 | } 541 | } 542 | }, 543 | o: 99, 544 | p: 1/0, 545 | q: [] 546 | }, 547 | l: undefined, 548 | m: null 549 | } 550 | }, 551 | i: true, 552 | h: "false" 553 | } 554 | }, 555 | e: undefined, 556 | g: "", 557 | f: {}, 558 | h: "h", 559 | i: [] 560 | } 561 | ), true); 562 | 563 | equal(QUnit.equiv( 564 | { 565 | a: 1, 566 | b: null, 567 | c: [{}], 568 | d: { 569 | a: 3.14159, 570 | b: false, 571 | c: { 572 | d: 0, 573 | e: fn1, 574 | f: [[[]]], 575 | g: { 576 | j: { 577 | k: { 578 | n: { 579 | //r: "r", // different: missing a property 580 | s: [1,2,3], 581 | t: undefined, 582 | u: 0, 583 | v: { 584 | w: { 585 | x: { 586 | y: "Yahoo!", 587 | z: null 588 | } 589 | } 590 | } 591 | }, 592 | o: 99, 593 | p: 1/0, 594 | q: [] 595 | }, 596 | l: undefined, 597 | m: null 598 | } 599 | }, 600 | h: "false", 601 | i: true 602 | } 603 | }, 604 | e: undefined, 605 | f: {}, 606 | g: "", 607 | h: "h", 608 | i: [] 609 | }, 610 | { 611 | a: 1, 612 | b: null, 613 | c: [{}], 614 | d: { 615 | a: 3.14159, 616 | b: false, 617 | c: { 618 | d: 0, 619 | e: fn1, 620 | f: [[[]]], 621 | g: { 622 | j: { 623 | k: { 624 | n: { 625 | r: "r", 626 | s: [1,2,3], 627 | t: undefined, 628 | u: 0, 629 | v: { 630 | w: { 631 | x: { 632 | y: "Yahoo!", 633 | z: null 634 | } 635 | } 636 | } 637 | }, 638 | o: 99, 639 | p: 1/0, 640 | q: [] 641 | }, 642 | l: undefined, 643 | m: null 644 | } 645 | }, 646 | h: "false", 647 | i: true 648 | } 649 | }, 650 | e: undefined, 651 | f: {}, 652 | g: "", 653 | h: "h", 654 | i: [] 655 | } 656 | ), false); 657 | 658 | equal(QUnit.equiv( 659 | { 660 | a: 1, 661 | b: null, 662 | c: [{}], 663 | d: { 664 | a: 3.14159, 665 | b: false, 666 | c: { 667 | d: 0, 668 | e: fn1, 669 | f: [[[]]], 670 | g: { 671 | j: { 672 | k: { 673 | n: { 674 | r: "r", 675 | s: [1,2,3], 676 | t: undefined, 677 | u: 0, 678 | v: { 679 | w: { 680 | x: { 681 | y: "Yahoo!", 682 | z: null 683 | } 684 | } 685 | } 686 | }, 687 | o: 99, 688 | p: 1/0, 689 | q: [] 690 | }, 691 | l: undefined, 692 | m: null 693 | } 694 | }, 695 | h: "false", 696 | i: true 697 | } 698 | }, 699 | e: undefined, 700 | f: {}, 701 | g: "", 702 | h: "h", 703 | i: [] 704 | }, 705 | { 706 | a: 1, 707 | b: null, 708 | c: [{}], 709 | d: { 710 | a: 3.14159, 711 | b: false, 712 | c: { 713 | d: 0, 714 | e: fn1, 715 | f: [[[]]], 716 | g: { 717 | j: { 718 | k: { 719 | n: { 720 | r: "r", 721 | s: [1,2,3], 722 | //t: undefined, // different: missing a property with an undefined value 723 | u: 0, 724 | v: { 725 | w: { 726 | x: { 727 | y: "Yahoo!", 728 | z: null 729 | } 730 | } 731 | } 732 | }, 733 | o: 99, 734 | p: 1/0, 735 | q: [] 736 | }, 737 | l: undefined, 738 | m: null 739 | } 740 | }, 741 | h: "false", 742 | i: true 743 | } 744 | }, 745 | e: undefined, 746 | f: {}, 747 | g: "", 748 | h: "h", 749 | i: [] 750 | } 751 | ), false); 752 | 753 | equal(QUnit.equiv( 754 | { 755 | a: 1, 756 | b: null, 757 | c: [{}], 758 | d: { 759 | a: 3.14159, 760 | b: false, 761 | c: { 762 | d: 0, 763 | e: fn1, 764 | f: [[[]]], 765 | g: { 766 | j: { 767 | k: { 768 | n: { 769 | r: "r", 770 | s: [1,2,3], 771 | t: undefined, 772 | u: 0, 773 | v: { 774 | w: { 775 | x: { 776 | y: "Yahoo!", 777 | z: null 778 | } 779 | } 780 | } 781 | }, 782 | o: 99, 783 | p: 1/0, 784 | q: [] 785 | }, 786 | l: undefined, 787 | m: null 788 | } 789 | }, 790 | h: "false", 791 | i: true 792 | } 793 | }, 794 | e: undefined, 795 | f: {}, 796 | g: "", 797 | h: "h", 798 | i: [] 799 | }, 800 | { 801 | a: 1, 802 | b: null, 803 | c: [{}], 804 | d: { 805 | a: 3.14159, 806 | b: false, 807 | c: { 808 | d: 0, 809 | e: fn1, 810 | f: [[[]]], 811 | g: { 812 | j: { 813 | k: { 814 | n: { 815 | r: "r", 816 | s: [1,2,3], 817 | t: undefined, 818 | u: 0, 819 | v: { 820 | w: { 821 | x: { 822 | y: "Yahoo!", 823 | z: null 824 | } 825 | } 826 | } 827 | }, 828 | o: 99, 829 | p: 1/0, 830 | q: {} // different was [] 831 | }, 832 | l: undefined, 833 | m: null 834 | } 835 | }, 836 | h: "false", 837 | i: true 838 | } 839 | }, 840 | e: undefined, 841 | f: {}, 842 | g: "", 843 | h: "h", 844 | i: [] 845 | } 846 | ), false); 847 | 848 | var same1 = { 849 | a: [ 850 | "string", null, 0, "1", 1, { 851 | prop: null, 852 | foo: [1,2,null,{}, [], [1,2,3]], 853 | bar: undefined 854 | }, 3, "Hey!", "Κάνε πάντα γνωÏ�ίζουμε ας των, μηχανής επιδιόÏ�θωσης επιδιοÏ�θώσεις ÏŽÏ‚ μια. Κλπ ας" 855 | ], 856 | unicode: "è€� 汉语中存在 港澳和海外的å�Žäººåœˆä¸­ 贵州 我去了书店 现在尚有争", 857 | b: "b", 858 | c: fn1 859 | }; 860 | 861 | var same2 = { 862 | a: [ 863 | "string", null, 0, "1", 1, { 864 | prop: null, 865 | foo: [1,2,null,{}, [], [1,2,3]], 866 | bar: undefined 867 | }, 3, "Hey!", "Κάνε πάντα γνωÏ�ίζουμε ας των, μηχανής επιδιόÏ�θωσης επιδιοÏ�θώσεις ÏŽÏ‚ μια. Κλπ ας" 868 | ], 869 | unicode: "è€� 汉语中存在 港澳和海外的å�Žäººåœˆä¸­ 贵州 我去了书店 现在尚有争", 870 | b: "b", 871 | c: fn1 872 | }; 873 | 874 | var diff1 = { 875 | a: [ 876 | "string", null, 0, "1", 1, { 877 | prop: null, 878 | foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array 879 | bar: undefined 880 | }, 3, "Hey!", "Κάνε πάντα γνωÏ�ίζουμε ας των, μηχανής επιδιόÏ�θωσης επιδιοÏ�θώσεις ÏŽÏ‚ μια. Κλπ ας" 881 | ], 882 | unicode: "è€� 汉语中存在 港澳和海外的å�Žäººåœˆä¸­ 贵州 我去了书店 现在尚有争", 883 | b: "b", 884 | c: fn1 885 | }; 886 | 887 | var diff2 = { 888 | a: [ 889 | "string", null, 0, "1", 1, { 890 | prop: null, 891 | foo: [1,2,null,{}, [], [1,2,3]], 892 | newprop: undefined, // different: newprop was added 893 | bar: undefined 894 | }, 3, "Hey!", "Κάνε πάντα γνωÏ�ίζουμε ας των, μηχανής επιδιόÏ�θωσης επιδιοÏ�θώσεις ÏŽÏ‚ μια. Κλπ ας" 895 | ], 896 | unicode: "è€� 汉语中存在 港澳和海外的å�Žäººåœˆä¸­ 贵州 我去了书店 现在尚有争", 897 | b: "b", 898 | c: fn1 899 | }; 900 | 901 | var diff3 = { 902 | a: [ 903 | "string", null, 0, "1", 1, { 904 | prop: null, 905 | foo: [1,2,null,{}, [], [1,2,3]], 906 | bar: undefined 907 | }, 3, "Hey!", "Κάνε πάντα γνωÏ�ίζουμε ας των, μηχανής επιδιόÏ�θωσης επιδιοÏ�θώσεις ÏŽÏ‚ μια. Κλπ α" // different: missing last char 908 | ], 909 | unicode: "è€� 汉语中存在 港澳和海外的å�Žäººåœˆä¸­ 贵州 我去了书店 现在尚有争", 910 | b: "b", 911 | c: fn1 912 | }; 913 | 914 | var diff4 = { 915 | a: [ 916 | "string", null, 0, "1", 1, { 917 | prop: null, 918 | foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null 919 | bar: undefined 920 | }, 3, "Hey!", "Κάνε πάντα γνωÏ�ίζουμε ας των, μηχανής επιδιόÏ�θωσης επιδιοÏ�θώσεις ÏŽÏ‚ μια. Κλπ ας" 921 | ], 922 | unicode: "è€� 汉语中存在 港澳和海外的å�Žäººåœˆä¸­ 贵州 我去了书店 现在尚有争", 923 | b: "b", 924 | c: fn1 925 | }; 926 | 927 | var diff5 = { 928 | a: [ 929 | "string", null, 0, "1", 1, { 930 | prop: null, 931 | foo: [1,2,null,{}, [], [1,2,3]], 932 | bat: undefined // different: property name not "bar" 933 | }, 3, "Hey!", "Κάνε πάντα γνωÏ�ίζουμε ας των, μηχανής επιδιόÏ�θωσης επιδιοÏ�θώσεις ÏŽÏ‚ μια. Κλπ ας" 934 | ], 935 | unicode: "è€� 汉语中存在 港澳和海外的å�Žäººåœˆä¸­ 贵州 我去了书店 现在尚有争", 936 | b: "b", 937 | c: fn1 938 | }; 939 | 940 | equal(QUnit.equiv(same1, same2), true); 941 | equal(QUnit.equiv(same2, same1), true); 942 | equal(QUnit.equiv(same2, diff1), false); 943 | equal(QUnit.equiv(diff1, same2), false); 944 | 945 | equal(QUnit.equiv(same1, diff1), false); 946 | equal(QUnit.equiv(same1, diff2), false); 947 | equal(QUnit.equiv(same1, diff3), false); 948 | equal(QUnit.equiv(same1, diff3), false); 949 | equal(QUnit.equiv(same1, diff4), false); 950 | equal(QUnit.equiv(same1, diff5), false); 951 | equal(QUnit.equiv(diff5, diff1), false); 952 | }); 953 | 954 | 955 | test("Complex Arrays.", function() { 956 | 957 | function fn() { 958 | } 959 | 960 | equal(QUnit.equiv( 961 | [1, 2, 3, true, {}, null, [ 962 | { 963 | a: ["", '1', 0] 964 | }, 965 | 5, 6, 7 966 | ], "foo"], 967 | [1, 2, 3, true, {}, null, [ 968 | { 969 | a: ["", '1', 0] 970 | }, 971 | 5, 6, 7 972 | ], "foo"]), 973 | true); 974 | 975 | equal(QUnit.equiv( 976 | [1, 2, 3, true, {}, null, [ 977 | { 978 | a: ["", '1', 0] 979 | }, 980 | 5, 6, 7 981 | ], "foo"], 982 | [1, 2, 3, true, {}, null, [ 983 | { 984 | b: ["", '1', 0] // not same property name 985 | }, 986 | 5, 6, 7 987 | ], "foo"]), 988 | false); 989 | 990 | var a = [{ 991 | b: fn, 992 | c: false, 993 | "do": "reserved word", 994 | "for": { 995 | ar: [3,5,9,"hey!", [], { 996 | ar: [1,[ 997 | 3,4,6,9, null, [], [] 998 | ]], 999 | e: fn, 1000 | f: undefined 1001 | }] 1002 | }, 1003 | e: 0.43445 1004 | }, 5, "string", 0, fn, false, null, undefined, 0, [ 1005 | 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 1006 | ], [], [[[], "foo", null, { 1007 | n: 1/0, 1008 | z: { 1009 | a: [3,4,5,6,"yep!", undefined, undefined], 1010 | b: {} 1011 | } 1012 | }, {}]]]; 1013 | 1014 | equal(QUnit.equiv(a, 1015 | [{ 1016 | b: fn, 1017 | c: false, 1018 | "do": "reserved word", 1019 | "for": { 1020 | ar: [3,5,9,"hey!", [], { 1021 | ar: [1,[ 1022 | 3,4,6,9, null, [], [] 1023 | ]], 1024 | e: fn, 1025 | f: undefined 1026 | }] 1027 | }, 1028 | e: 0.43445 1029 | }, 5, "string", 0, fn, false, null, undefined, 0, [ 1030 | 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 1031 | ], [], [[[], "foo", null, { 1032 | n: 1/0, 1033 | z: { 1034 | a: [3,4,5,6,"yep!", undefined, undefined], 1035 | b: {} 1036 | } 1037 | }, {}]]]), true); 1038 | 1039 | equal(QUnit.equiv(a, 1040 | [{ 1041 | b: fn, 1042 | c: false, 1043 | "do": "reserved word", 1044 | "for": { 1045 | ar: [3,5,9,"hey!", [], { 1046 | ar: [1,[ 1047 | 3,4,6,9, null, [], [] 1048 | ]], 1049 | e: fn, 1050 | f: undefined 1051 | }] 1052 | }, 1053 | e: 0.43445 1054 | }, 5, "string", 0, fn, false, null, undefined, 0, [ 1055 | 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0 // different: [[[[[2]]]]] instead of [[[[[3]]]]] 1056 | ], [], [[[], "foo", null, { 1057 | n: 1/0, 1058 | z: { 1059 | a: [3,4,5,6,"yep!", undefined, undefined], 1060 | b: {} 1061 | } 1062 | }, {}]]]), false); 1063 | 1064 | equal(QUnit.equiv(a, 1065 | [{ 1066 | b: fn, 1067 | c: false, 1068 | "do": "reserved word", 1069 | "for": { 1070 | ar: [3,5,9,"hey!", [], { 1071 | ar: [1,[ 1072 | 3,4,6,9, null, [], [] 1073 | ]], 1074 | e: fn, 1075 | f: undefined 1076 | }] 1077 | }, 1078 | e: 0.43445 1079 | }, 5, "string", 0, fn, false, null, undefined, 0, [ 1080 | 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 1081 | ], [], [[[], "foo", null, { 1082 | n: -1/0, // different, -Infinity instead of Infinity 1083 | z: { 1084 | a: [3,4,5,6,"yep!", undefined, undefined], 1085 | b: {} 1086 | } 1087 | }, {}]]]), false); 1088 | 1089 | equal(QUnit.equiv(a, 1090 | [{ 1091 | b: fn, 1092 | c: false, 1093 | "do": "reserved word", 1094 | "for": { 1095 | ar: [3,5,9,"hey!", [], { 1096 | ar: [1,[ 1097 | 3,4,6,9, null, [], [] 1098 | ]], 1099 | e: fn, 1100 | f: undefined 1101 | }] 1102 | }, 1103 | e: 0.43445 1104 | }, 5, "string", 0, fn, false, null, undefined, 0, [ 1105 | 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 1106 | ], [], [[[], "foo", { // different: null is missing 1107 | n: 1/0, 1108 | z: { 1109 | a: [3,4,5,6,"yep!", undefined, undefined], 1110 | b: {} 1111 | } 1112 | }, {}]]]), false); 1113 | 1114 | equal(QUnit.equiv(a, 1115 | [{ 1116 | b: fn, 1117 | c: false, 1118 | "do": "reserved word", 1119 | "for": { 1120 | ar: [3,5,9,"hey!", [], { 1121 | ar: [1,[ 1122 | 3,4,6,9, null, [], [] 1123 | ]], 1124 | e: fn 1125 | // different: missing property f: undefined 1126 | }] 1127 | }, 1128 | e: 0.43445 1129 | }, 5, "string", 0, fn, false, null, undefined, 0, [ 1130 | 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 1131 | ], [], [[[], "foo", null, { 1132 | n: 1/0, 1133 | z: { 1134 | a: [3,4,5,6,"yep!", undefined, undefined], 1135 | b: {} 1136 | } 1137 | }, {}]]]), false); 1138 | }); 1139 | 1140 | 1141 | test("Prototypal inheritance", function() { 1142 | function Gizmo(id) { 1143 | this.id = id; 1144 | } 1145 | 1146 | function Hoozit(id) { 1147 | this.id = id; 1148 | } 1149 | Hoozit.prototype = new Gizmo(); 1150 | 1151 | var gizmo = new Gizmo("ok"); 1152 | var hoozit = new Hoozit("ok"); 1153 | 1154 | // Try this test many times after test on instances that hold function 1155 | // to make sure that our code does not mess with last object constructor memoization. 1156 | equal(QUnit.equiv(function () {}, function () {}), false); 1157 | 1158 | // Hoozit inherit from Gizmo 1159 | // hoozit instanceof Hoozit; // true 1160 | // hoozit instanceof Gizmo; // true 1161 | equal(QUnit.equiv(hoozit, gizmo), true); 1162 | 1163 | Gizmo.prototype.bar = true; // not a function just in case we skip them 1164 | 1165 | // Hoozit inherit from Gizmo 1166 | // They are equivalent 1167 | equal(QUnit.equiv(hoozit, gizmo), true); 1168 | 1169 | // Make sure this is still true !important 1170 | // The reason for this is that I forgot to reset the last 1171 | // caller to where it were called from. 1172 | equal(QUnit.equiv(function () {}, function () {}), false); 1173 | 1174 | // Make sure this is still true !important 1175 | equal(QUnit.equiv(hoozit, gizmo), true); 1176 | 1177 | Hoozit.prototype.foo = true; // not a function just in case we skip them 1178 | 1179 | // Gizmo does not inherit from Hoozit 1180 | // gizmo instanceof Gizmo; // true 1181 | // gizmo instanceof Hoozit; // false 1182 | // They are not equivalent 1183 | equal(QUnit.equiv(hoozit, gizmo), false); 1184 | 1185 | // Make sure this is still true !important 1186 | equal(QUnit.equiv(function () {}, function () {}), false); 1187 | }); 1188 | 1189 | 1190 | test("Instances", function() { 1191 | function A() {} 1192 | var a1 = new A(); 1193 | var a2 = new A(); 1194 | 1195 | function B() { 1196 | this.fn = function () {}; 1197 | } 1198 | var b1 = new B(); 1199 | var b2 = new B(); 1200 | 1201 | equal(QUnit.equiv(a1, a2), true, "Same property, same constructor"); 1202 | 1203 | // b1.fn and b2.fn are functions but they are different references 1204 | // But we decided to skip function for instances. 1205 | equal(QUnit.equiv(b1, b2), true, "Same property, same constructor"); 1206 | equal(QUnit.equiv(a1, b1), false, "Same properties but different constructor"); // failed 1207 | 1208 | function Car(year) { 1209 | var privateVar = 0; 1210 | this.year = year; 1211 | this.isOld = function() { 1212 | return year > 10; 1213 | }; 1214 | } 1215 | 1216 | function Human(year) { 1217 | var privateVar = 1; 1218 | this.year = year; 1219 | this.isOld = function() { 1220 | return year > 80; 1221 | }; 1222 | } 1223 | 1224 | var car = new Car(30); 1225 | var carSame = new Car(30); 1226 | var carDiff = new Car(10); 1227 | var human = new Human(30); 1228 | 1229 | var diff = { 1230 | year: 30 1231 | }; 1232 | 1233 | var same = { 1234 | year: 30, 1235 | isOld: function () {} 1236 | }; 1237 | 1238 | equal(QUnit.equiv(car, car), true); 1239 | equal(QUnit.equiv(car, carDiff), false); 1240 | equal(QUnit.equiv(car, carSame), true); 1241 | equal(QUnit.equiv(car, human), false); 1242 | }); 1243 | 1244 | 1245 | test("Complex Instances Nesting (with function value in literals and/or in nested instances)", function() { 1246 | function A(fn) { 1247 | this.a = {}; 1248 | this.fn = fn; 1249 | this.b = {a: []}; 1250 | this.o = {}; 1251 | this.fn1 = fn; 1252 | } 1253 | function B(fn) { 1254 | this.fn = fn; 1255 | this.fn1 = function () {}; 1256 | this.a = new A(function () {}); 1257 | } 1258 | 1259 | function fnOutside() { 1260 | } 1261 | 1262 | function C(fn) { 1263 | function fnInside() { 1264 | } 1265 | this.x = 10; 1266 | this.fn = fn; 1267 | this.fn1 = function () {}; 1268 | this.fn2 = fnInside; 1269 | this.fn3 = { 1270 | a: true, 1271 | b: fnOutside // ok make reference to a function in all instances scope 1272 | }; 1273 | this.o1 = {}; 1274 | 1275 | // This function will be ignored. 1276 | // Even if it is not visible for all instances (e.g. locked in a closures), 1277 | // it is from a property that makes part of an instance (e.g. from the C constructor) 1278 | this.b1 = new B(function () {}); 1279 | this.b2 = new B({ 1280 | x: { 1281 | b2: new B(function() {}) 1282 | } 1283 | }); 1284 | } 1285 | 1286 | function D(fn) { 1287 | function fnInside() { 1288 | } 1289 | this.x = 10; 1290 | this.fn = fn; 1291 | this.fn1 = function () {}; 1292 | this.fn2 = fnInside; 1293 | this.fn3 = { 1294 | a: true, 1295 | b: fnOutside, // ok make reference to a function in all instances scope 1296 | 1297 | // This function won't be ingored. 1298 | // It isn't visible for all C insances 1299 | // and it is not in a property of an instance. (in an Object instances e.g. the object literal) 1300 | c: fnInside 1301 | }; 1302 | this.o1 = {}; 1303 | 1304 | // This function will be ignored. 1305 | // Even if it is not visible for all instances (e.g. locked in a closures), 1306 | // it is from a property that makes part of an instance (e.g. from the C constructor) 1307 | this.b1 = new B(function () {}); 1308 | this.b2 = new B({ 1309 | x: { 1310 | b2: new B(function() {}) 1311 | } 1312 | }); 1313 | } 1314 | 1315 | function E(fn) { 1316 | function fnInside() { 1317 | } 1318 | this.x = 10; 1319 | this.fn = fn; 1320 | this.fn1 = function () {}; 1321 | this.fn2 = fnInside; 1322 | this.fn3 = { 1323 | a: true, 1324 | b: fnOutside // ok make reference to a function in all instances scope 1325 | }; 1326 | this.o1 = {}; 1327 | 1328 | // This function will be ignored. 1329 | // Even if it is not visible for all instances (e.g. locked in a closures), 1330 | // it is from a property that makes part of an instance (e.g. from the C constructor) 1331 | this.b1 = new B(function () {}); 1332 | this.b2 = new B({ 1333 | x: { 1334 | b1: new B({a: function() {}}), 1335 | b2: new B(function() {}) 1336 | } 1337 | }); 1338 | } 1339 | 1340 | 1341 | var a1 = new A(function () {}); 1342 | var a2 = new A(function () {}); 1343 | equal(QUnit.equiv(a1, a2), true); 1344 | 1345 | equal(QUnit.equiv(a1, a2), true); // different instances 1346 | 1347 | var b1 = new B(function () {}); 1348 | var b2 = new B(function () {}); 1349 | equal(QUnit.equiv(b1, b2), true); 1350 | 1351 | var c1 = new C(function () {}); 1352 | var c2 = new C(function () {}); 1353 | equal(QUnit.equiv(c1, c2), true); 1354 | 1355 | var d1 = new D(function () {}); 1356 | var d2 = new D(function () {}); 1357 | equal(QUnit.equiv(d1, d2), false); 1358 | 1359 | var e1 = new E(function () {}); 1360 | var e2 = new E(function () {}); 1361 | equal(QUnit.equiv(e1, e2), false); 1362 | 1363 | }); 1364 | 1365 | 1366 | test('object with references to self wont loop', function(){ 1367 | var circularA = { 1368 | abc:null 1369 | }, circularB = { 1370 | abc:null 1371 | }; 1372 | circularA.abc = circularA; 1373 | circularB.abc = circularB; 1374 | equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)"); 1375 | 1376 | circularA.def = 1; 1377 | circularB.def = 1; 1378 | equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)"); 1379 | 1380 | circularA.def = 1; 1381 | circularB.def = 0; 1382 | equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object (unambigous test)"); 1383 | }); 1384 | 1385 | test('array with references to self wont loop', function(){ 1386 | var circularA = [], 1387 | circularB = []; 1388 | circularA.push(circularA); 1389 | circularB.push(circularB); 1390 | equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)"); 1391 | 1392 | circularA.push( 'abc' ); 1393 | circularB.push( 'abc' ); 1394 | equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)"); 1395 | 1396 | circularA.push( 'hello' ); 1397 | circularB.push( 'goodbye' ); 1398 | equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on array (unambigous test)"); 1399 | }); 1400 | 1401 | test('mixed object/array with references to self wont loop', function(){ 1402 | var circularA = [{abc:null}], 1403 | circularB = [{abc:null}]; 1404 | circularA[0].abc = circularA; 1405 | circularB[0].abc = circularB; 1406 | 1407 | circularA.push(circularA); 1408 | circularB.push(circularB); 1409 | equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)"); 1410 | 1411 | circularA[0].def = 1; 1412 | circularB[0].def = 1; 1413 | equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)"); 1414 | 1415 | circularA[0].def = 1; 1416 | circularB[0].def = 0; 1417 | equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambigous test)"); 1418 | }); 1419 | 1420 | test("Test that must be done at the end because they extend some primitive's prototype", function() { 1421 | // Try that a function looks like our regular expression. 1422 | // This tests if we check that a and b are really both instance of RegExp 1423 | Function.prototype.global = true; 1424 | Function.prototype.multiline = true; 1425 | Function.prototype.ignoreCase = false; 1426 | Function.prototype.source = "my regex"; 1427 | var re = /my regex/gm; 1428 | equal(QUnit.equiv(re, function () {}), false, "A function that looks that a regex isn't a regex"); 1429 | // This test will ensures it works in both ways, and ALSO especially that we can make differences 1430 | // between RegExp and Function constructor because typeof on a RegExpt instance is "function" 1431 | equal(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different"); 1432 | }); 1433 | --------------------------------------------------------------------------------