Permalink
Browse files

Add a few basic tests

  • Loading branch information...
1 parent aa6ed80 commit 81f6dac12c25c591df19dbef163092e002e77859 @mhuggins committed Feb 17, 2013
Showing with 82 additions and 0 deletions.
  1. +16 −0 test/index.html
  2. +66 −0 test/tests.js
View
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>jQuery-countTo Test Suite</title>
+ <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css">
+</head>
+<body>
+ <div id="qunit"></div>
+ <div id="qunit-fixture"></div>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
+ <script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
+ <script src="../jquery.countTo.js"></script>
+ <script src="tests.js"></script>
+</body>
+</html>
View
@@ -0,0 +1,66 @@
+var timer;
+
+// test to ensure DOM options are respected
+module('DOM options');
+timer = $('<div data-from="1" data-to="3" data-speed="3000" data-refresh-interval="1000"/>');
+runTests(timer);
+
+// test to ensure JS options are respected
+module('JS options');
+timer = $('<div/>');
+runTests(timer, {
+ from: 1,
+ to: 3,
+ speed: 3000,
+ refreshInterval: 1000
+});
+
+// test to ensure JS options override DOM options
+module('DOM and JS options');
+timer = $('<div data-from="0" data-to="5" data-speed="1000" data-refresh-interval="500"/>');
+runTests(timer, {
+ from: 1,
+ to: 3,
+ speed: 3000,
+ refreshInterval: 1000
+});
+
+function runTests(element, options) {
+ element = $(element);
+ options = options || {};
+
+ asyncTest('onComplete is called when counting completes', 4, function () {
+ element.countTo($.extend({}, options, {
+ onComplete: function (value) {
+ ok(true, 'onComplete was called');
+ ok(this == element[0], 'this is the updated dom element');
+ ok(value == 3, 'value matches data-to');
+ ok(this.innerText == 3, 'innerText matches data-to');
+ start();
+ }
+ }));
+ });
+
+ asyncTest('onUpdate is called once per refresh', 3, function () {
+ element.countTo($.extend({}, options, {
+ onUpdate: function () {
+ ok(true, 'onUpdate was called');
+ },
+ onComplete: function () {
+ start();
+ }
+ }));
+ });
+
+ asyncTest('custom formatter is called', 1, function () {
+ element.countTo($.extend({}, options, {
+ formatter: function () {
+ return 'foobar';
+ },
+ onComplete: function () {
+ ok(this.innerText == 'foobar', 'innerText matches formatted value');
+ start();
+ }
+ }));
+ });
+}

0 comments on commit 81f6dac

Please sign in to comment.