diff options
-rw-r--r-- | .travis.yml | 9 | ||||
-rw-r--r-- | HISTORY.md | 1 | ||||
-rw-r--r-- | bower.json | 10 | ||||
-rw-r--r-- | package.json | 4 | ||||
-rw-r--r-- | test/index.html | 39 | ||||
-rw-r--r-- | test/test.js | 94 |
6 files changed, 48 insertions, 109 deletions
diff --git a/.travis.yml b/.travis.yml index efd3a59..871840e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,8 @@ # v1.3.21 June 23, 2014 # https://github.com/bevry/base language: node_js -# ensure npm is the latest (handled via npm install -g npm) -# ensure coffee-script is installed (needed for cake commands) -# ensure dev dependencies are installed (handled via npm install) -# ensure test dependencies are installed (handled via cake install) -install: - - npm install grunt-cli -g - - npm install -script: "npm test" node_js: + - "0.11" - "0.10" cache: directories: @@ -2,6 +2,7 @@ ## v2.0.x - Update documentation +- Switched to [Mocha](http://mochajs.org) for automated testing ## v2.0.0-beta.1 October 16, 2014 - Less dependency on Grunt @@ -17,13 +17,5 @@ ], "dependencies": { "jquery": "*" - }, - "devDependencies": { - "eslint": "~0.9.2", - "grunt": "~0.4.5", - "grunt-contrib-qunit": "~0.5.2", - "projectz": "~0.3.15", - "uglify-js": "~2.4.15", - "qunitjs": "~1.16.0" } -}
\ No newline at end of file +} diff --git a/package.json b/package.json index 194948c..0086528 100644 --- a/package.json +++ b/package.json @@ -55,14 +55,12 @@ "mocha": "*", "mocha-jsdom": "^0.2.0", "projectz": "~0.3.15", - "qunitjs": "~1.16.0", "uglify-js": "~2.4.15" }, "scripts": { "pretest": "./node_modules/.bin/eslint jquery.once.js test/test.js", "test": "./node_modules/.bin/mocha", "projectz": "./node_modules/.bin/projectz compile", - "release": "./node_modules/.bin/uglifyjs jquery.once.js -o jquery.once.min.js --comments --source-map jquery.once.min.js.map --mangle", - "jsdoc": "jsdoc jquery.once.js README.md" + "release": "./node_modules/.bin/uglifyjs jquery.once.js -o jquery.once.min.js --comments --source-map jquery.once.min.js.map --mangle" } } diff --git a/test/index.html b/test/index.html deleted file mode 100644 index 6a0293f..0000000 --- a/test/index.html +++ /dev/null @@ -1,39 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <title>jQuery Once - Test Suite</title> - <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css"> -</head> -<body id="body"> - <div id="qunit"></div> - <div id="qunit-fixture"> - - <div id="test1"> - <p>This is <span>Test 1</span>.</p> - </div> - - <div id="test2"> - <p>This is <span>Test 2</span>.</p> - </div> - - <div id="test3"> - <p>This is <span>Test 3</span>.</p> - </div> - - <div id="test4"> - <p>This is <span>Test 4</span>.</p> - </div> - - <div id="test5"> - <p>This is <span>Test 5</span>.</p> - <p>This is <span>Test 5 #2</span>.</p> - </div> - - </div> - - <script src="../node_modules/jquery/dist/jquery.js"></script> - <script src="../node_modules/qunitjs/qunit/qunit.js"></script> - <script src="../jquery.once.js"></script> - <script src="test.js"></script> -</body> -</html> diff --git a/test/test.js b/test/test.js index c462a27..e0c4711 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,9 @@ var jsdom = require("mocha-jsdom"); var assert = require("assert"); +/** + * Automated tests for jQuery Once. + */ describe("jQuery Once", function() { "use strict"; @@ -22,10 +25,15 @@ describe("jQuery Once", function() { require("../jquery.once.js"); }); - it("should require ID to be a string", function () { + /** + * Before each test, reset the document body so that there is fresh data. + */ + beforeEach(function() { // Build the body HTML. - document.body.innerHTML = "<p>This is <span>Test 1</span>.</p>"; + document.body.innerHTML = "<p>This is the <span>Test</span>.</p>"; + }); + it("should require ID to be a string", function () { // Expect it to throw an error. assert.throws(function() { $("span").once(function () { @@ -35,9 +43,6 @@ describe("jQuery Once", function() { }); it("properly executes .once('test2')", function () { - // Prepare the document body. - document.body.innerHTML = "<p>This is <span>Test 2</span>.</p>"; - // Create one once('test2') call. $("span").once("test2").data("test2", "foo"); @@ -50,9 +55,6 @@ describe("jQuery Once", function() { }); it("is called only once with an ID", function() { - // Prepare the document body. - document.body.innerHTML = "<p>This is <span>Test 3</span>.</p>"; - // Count the number of times once() was called. $("span").data("count", 0); @@ -78,65 +80,57 @@ describe("jQuery Once", function() { // Create the once() callback. var callback = function() { - $("span").data("once", $("span").data('once') + 1); + $("span").data("once", $("span").data("once") + 1); }; // Call once() a bunch of times. for (var i = 0; i < 10; i++) { - $('#test2 span').once().each(callback); + $("span").once().each(callback); } // Verify that it was only called once. - var count = $('#test2 span').data('once'); - ok(count === 1, 'It was called ' + count + ' times.'); + var count = $("span").data("once"); + assert.equal(count, 1, "It was called " + count + " times."); }); -}); - -/* + it("retrieves empty once data correctly", function() { + // Verify that the element starts without the class. + var hasData = $("span").data("jquery-once-test3"); + assert(!hasData, "Value not applied in the beginning."); -test("Apply the value to data correctly", function() { - // Verify that the element starts without the class. - var hasData = $('#test3 span').data('jquery-once-test3'); - ok(!hasData, 'Value not applied in the beginning.'); + // Create one once() call. + $("span").once("test3"); - // Create one once() call. - $('#test3 span').once('test3'); + // Verify the data is applied. + hasData = $("span").data("jquery-once-test3"); + assert(hasData, "The value is properly applied after once()."); + }); - // Verify the data is applied. - hasData = $('#test3 span').data('jquery-once-test3'); - ok(hasData, 'The value is properly applied after once().'); -}); + it("calls removeOnce() correctly", function() { + // Create one once() call. + $("span").once("test4"); -test("Remove the value from attribute correctly", function() { - // Create one once() call. - $('#test4 span').once('test4'); + // Verify the data is applied. + var hasData = $("span").data("jquery-once-test4"); + assert(hasData, "The value is properly applied after once()."); - // Verify the data is applied. - var hasData = $('#test4 span').data('jquery-once-test4'); - ok(hasData, 'The value is properly applied after once().'); + // Remove the once property. + $("span").removeOnce("test4"); + hasData = $("span").data("jquery-once-test4"); + assert(!hasData, "The value is properly removed when called removeOnce()."); + }); - // Remove the once property. - $('#test4 span').removeOnce('test4'); - hasData = $('#test4 span').data('jquery-once-test4'); - ok(!hasData, 'The value is properly removed when called removeOnce().'); -}); + it("calls findOnce() correctly", function() { + // Append an additional span to the end. + document.body.innerHTML += "<p>This is the <span>Test 2</span>.</p>"; -test("Finding elements correctly through findOnce()", function() { - // Create one once() call. - $('#test5 span').once('test5'); + // Create one once() call. + $("span").once("test5").data("foo", "bar"); - // Find the once'd element through the callback. - var elements = $('span').findOnce('test5').each(function() { - var hasData = $(this).data('jquery-once-test5'); - ok(hasData, 'Finding the correct span element after once() through callback.'); + // Find the once'd elements. + $("span").findOnce("test5").each(function() { + assert.equal($(this).data("foo"), "bar", "Found correct span data."); + }); }); - // Find the once'd element without the callback. - elements = $('span').findOnce('test5'); - elements.each(function() { - var hasData = $(this).data('jquery-once-test5'); - ok(hasData, 'Finding the correct span element after once().'); - }); }); -*/ |