[devtools] qunit: use new assert APIs
authorRémi Cardona <remi.cardona@logilab.fr>
Wed, 20 May 2015 15:45:43 +0200
changeset 10429 98ea2b865210
parent 10428 c961a301a90b
child 10430 2b1ea3e8e080
[devtools] qunit: use new assert APIs test functions now accept an "assert" argument which exposes QUnit's assert methods: assert.{expect,equal,deepEqual,ok} Related to #5533333.
devtools/test/data/js_examples/test_simple_failure.js
devtools/test/data/js_examples/test_simple_success.js
devtools/test/data/js_examples/test_with_dep.js
devtools/test/data/js_examples/test_with_ordered_deps.js
web/test/jstests/test_ajax.js
web/test/jstests/test_htmlhelpers.js
web/test/jstests/test_utils.js
--- a/devtools/test/data/js_examples/test_simple_failure.js	Wed May 20 17:04:43 2015 +0200
+++ b/devtools/test/data/js_examples/test_simple_failure.js	Wed May 20 15:45:43 2015 +0200
@@ -2,17 +2,17 @@
 
   QUnit.module("air");
 
-  QUnit.test("test 1", function() {
-      equal(2, 4);
+  QUnit.test("test 1", function (assert) {
+      assert.equal(2, 4);
   });
 
-  QUnit.test("test 2", function() {
-      equal('', '45');
-      equal('1024', '32');
+  QUnit.test("test 2", function (assert) {
+      assert.equal('', '45');
+      assert.equal('1024', '32');
   });
 
   QUnit.module("able");
-  QUnit.test("test 3", function() {
-      deepEqual(1, 1);
+  QUnit.test("test 3", function (assert) {
+      assert.deepEqual(1, 1);
   });
 });
--- a/devtools/test/data/js_examples/test_simple_success.js	Wed May 20 17:04:43 2015 +0200
+++ b/devtools/test/data/js_examples/test_simple_success.js	Wed May 20 15:45:43 2015 +0200
@@ -2,16 +2,16 @@
 
   QUnit.module("air");
 
-  QUnit.test("test 1", function() {
-      equal(2, 2);
+  QUnit.test("test 1", function (assert) {
+      assert.equal(2, 2);
   });
 
-  QUnit.test("test 2", function() {
-      equal('45', '45');
+  QUnit.test("test 2", function (assert) {
+      assert.equal('45', '45');
   });
 
   QUnit.module("able");
-  QUnit.test("test 3", function() {
-      deepEqual(1, 1);
+  QUnit.test("test 3", function (assert) {
+      assert.deepEqual(1, 1);
   });
 });
--- a/devtools/test/data/js_examples/test_with_dep.js	Wed May 20 17:04:43 2015 +0200
+++ b/devtools/test/data/js_examples/test_with_dep.js	Wed May 20 15:45:43 2015 +0200
@@ -2,8 +2,8 @@
 
   QUnit.module("air");
 
-  QUnit.test("test 1", function() {
-      equal(a, 4);
+  QUnit.test("test 1", function (assert) {
+      assert.equal(a, 4);
   });
 
 });
--- a/devtools/test/data/js_examples/test_with_ordered_deps.js	Wed May 20 17:04:43 2015 +0200
+++ b/devtools/test/data/js_examples/test_with_ordered_deps.js	Wed May 20 15:45:43 2015 +0200
@@ -2,8 +2,8 @@
 
   QUnit.module("air");
 
-  QUnit.test("test 1", function() {
-      equal(b, 6);
+  QUnit.test("test 1", function (assert) {
+      assert.equal(b, 6);
   });
 
 });
--- a/web/test/jstests/test_ajax.js	Wed May 20 17:04:43 2015 +0200
+++ b/web/test/jstests/test_ajax.js	Wed May 20 15:45:43 2015 +0200
@@ -22,15 +22,15 @@
         });
     }
 
-    QUnit.test('test simple h1 inclusion (ajax_url0.html)', function() {
-        expect(3);
-        equal(jQuery('#qunit-fixture').children().length, 0);
+    QUnit.test('test simple h1 inclusion (ajax_url0.html)', function (assert) {
+        assert.expect(3);
+        assert.equal(jQuery('#qunit-fixture').children().length, 0);
         stop();
         jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html')
         .addCallback(function() {
                 try {
-                    equal(jQuery('#qunit-fixture').children().length, 1);
-                    equal(jQuery('#qunit-fixture h1').html(), 'Hello');
+                    assert.equal(jQuery('#qunit-fixture').children().length, 1);
+                    assert.equal(jQuery('#qunit-fixture h1').html(), 'Hello');
                 } finally {
                     start();
                 };
@@ -38,10 +38,10 @@
         );
     });
 
-    QUnit.test('test simple html head inclusion (ajax_url1.html)', function() {
-        expect(6);
+    QUnit.test('test simple html head inclusion (ajax_url1.html)', function (assert) {
+        assert.expect(6);
         var scriptsIncluded = jsSources();
-        equal(jQuery.inArray('http://foo.js', scriptsIncluded), - 1);
+        assert.equal(jQuery.inArray('http://foo.js', scriptsIncluded), - 1);
         stop();
         jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url1.html')
         .addCallback(function() {
@@ -49,12 +49,12 @@
                     var origLength = scriptsIncluded.length;
                     scriptsIncluded = jsSources();
                     // check that foo.js has been prepended to <head>
-                    equal(scriptsIncluded.length, origLength + 1);
-                    equal(scriptsIncluded.indexOf('http://foo.js'), 0);
+                    assert.equal(scriptsIncluded.length, origLength + 1);
+                    assert.equal(scriptsIncluded.indexOf('http://foo.js'), 0);
                     // check that <div class="ajaxHtmlHead"> has been removed
-                    equal(jQuery('#qunit-fixture').children().length, 1);
-                    equal(jQuery('div.ajaxHtmlHead').length, 0);
-                    equal(jQuery('#qunit-fixture h1').html(), 'Hello');
+                    assert.equal(jQuery('#qunit-fixture').children().length, 1);
+                    assert.equal(jQuery('div.ajaxHtmlHead').length, 0);
+                    assert.equal(jQuery('#qunit-fixture h1').html(), 'Hello');
                 } finally {
                     start();
                 };
@@ -62,23 +62,23 @@
         );
     });
 
-    QUnit.test('test addCallback', function() {
-        expect(3);
-        equal(jQuery('#qunit-fixture').children().length, 0);
+    QUnit.test('test addCallback', function (assert) {
+        assert.expect(3);
+        assert.equal(jQuery('#qunit-fixture').children().length, 0);
         stop();
         var d = jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html');
         d.addCallback(function() {
             try {
-                equal(jQuery('#qunit-fixture').children().length, 1);
-                equal(jQuery('#qunit-fixture h1').html(), 'Hello');
+                assert.equal(jQuery('#qunit-fixture').children().length, 1);
+                assert.equal(jQuery('#qunit-fixture h1').html(), 'Hello');
             } finally {
                 start();
             };
         });
     });
 
-    QUnit.test('test callback after synchronous request', function() {
-        expect(1);
+    QUnit.test('test callback after synchronous request', function (assert) {
+        assert.expect(1);
         var deferred = new Deferred();
         var result = jQuery.ajax({
             url: BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html',
@@ -94,22 +94,22 @@
         deferred.addCallback(function() {
             try {
                 // add an assertion to ensure the callback is executed
-                ok(true, "callback is executed");
+                assert.ok(true, "callback is executed");
             } finally {
                 start();
             };
         });
     });
 
-    QUnit.test('test addCallback with parameters', function() {
-        expect(3);
-        equal(jQuery('#qunit-fixture').children().length, 0);
+    QUnit.test('test addCallback with parameters', function (assert) {
+        assert.expect(3);
+        assert.equal(jQuery('#qunit-fixture').children().length, 0);
         stop();
         var d = jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html');
         d.addCallback(function(data, req, arg1, arg2) {
             try {
-                equal(arg1, 'Hello');
-                equal(arg2, 'world');
+                assert.equal(arg1, 'Hello');
+                assert.equal(arg2, 'world');
             } finally {
                 start();
             };
@@ -117,15 +117,15 @@
         'Hello', 'world');
     });
 
-    QUnit.test('test callback after synchronous request with parameters', function() {
-        expect(3);
+    QUnit.test('test callback after synchronous request with parameters', function (assert) {
+        assert.expect(3);
         var deferred = new Deferred();
         deferred.addCallback(function(data, req, arg1, arg2) {
             // add an assertion to ensure the callback is executed
             try {
-                ok(true, "callback is executed");
-                equal(arg1, 'Hello');
-                equal(arg2, 'world');
+                assert.ok(true, "callback is executed");
+                assert.equal(arg1, 'Hello');
+                assert.equal(arg2, 'world');
             } finally {
                 start();
             };
@@ -152,52 +152,52 @@
         });
     });
 
-  QUnit.test('test addErrback', function() {
-        expect(1);
+  QUnit.test('test addErrback', function (assert) {
+        assert.expect(1);
         stop();
         var d = jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/nonexistent.html');
         d.addCallback(function() {
             // should not be executed
-            ok(false, "callback is executed");
+            assert.ok(false, "callback is executed");
         });
         d.addErrback(function() {
             try {
-                ok(true, "errback is executed");
+                assert.ok(true, "errback is executed");
             } finally {
                 start();
             };
         });
     });
 
-    QUnit.test('test callback execution order', function() {
-        expect(3);
+    QUnit.test('test callback execution order', function (assert) {
+        assert.expect(3);
         var counter = 0;
         stop();
         var d = jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html');
         d.addCallback(function() {
                 try {
-                    equal(++counter, 1); // should be executed first
+                    assert.equal(++counter, 1); // should be executed first
                 } finally {
                     start();
                 };
             }
         );
         d.addCallback(function() {
-            equal(++counter, 2);
+            assert.equal(++counter, 2);
         });
         d.addCallback(function() {
-            equal(++counter, 3);
+            assert.equal(++counter, 3);
         });
     });
 
-    QUnit.test('test already included resources are ignored (ajax_url1.html)', function() {
-        expect(10);
+    QUnit.test('test already included resources are ignored (ajax_url1.html)', function (assert) {
+        assert.expect(10);
         var scriptsIncluded = jsSources();
         // NOTE:
-        equal(jQuery.inArray('http://foo.js', scriptsIncluded), -1);
-        equal(jQuery('head link').length, 1);
+        assert.equal(jQuery.inArray('http://foo.js', scriptsIncluded), -1);
+        assert.equal(jQuery('head link').length, 1);
         /* use endswith because in pytest context we have an absolute path */
-        ok(jQuery('head link').attr('href').endswith('/qunit.css'), 'qunit.css is loaded');
+        assert.ok(jQuery('head link').attr('href').endswith('/qunit.css'), 'qunit.css is loaded');
         stop();
         jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url1.html')
         .addCallback(function() {
@@ -205,16 +205,16 @@
                 scriptsIncluded = jsSources();
                 try {
                     // check that foo.js has been inserted in <head>
-                    equal(scriptsIncluded.length, origLength + 1);
-                    equal(scriptsIncluded.indexOf('http://foo.js'), 0);
+                    assert.equal(scriptsIncluded.length, origLength + 1);
+                    assert.equal(scriptsIncluded.indexOf('http://foo.js'), 0);
                     // check that <div class="ajaxHtmlHead"> has been removed
-                    equal(jQuery('#qunit-fixture').children().length, 1);
-                    equal(jQuery('div.ajaxHtmlHead').length, 0);
-                    equal(jQuery('#qunit-fixture h1').html(), 'Hello');
+                    assert.equal(jQuery('#qunit-fixture').children().length, 1);
+                    assert.equal(jQuery('div.ajaxHtmlHead').length, 0);
+                    assert.equal(jQuery('#qunit-fixture h1').html(), 'Hello');
                     // qunit.css is not added twice
-                    equal(jQuery('head link').length, 1);
+                    assert.equal(jQuery('head link').length, 1);
                     /* use endswith because in pytest context we have an absolute path */
-                    ok(jQuery('head link').attr('href').endswith('/qunit.css'), 'qunit.css is loaded');
+                    assert.ok(jQuery('head link').attr('href').endswith('/qunit.css'), 'qunit.css is loaded');
                 } finally {
                     start();
                 }
@@ -222,14 +222,14 @@
         );
     });
 
-    QUnit.test('test synchronous request loadRemote', function() {
+    QUnit.test('test synchronous request loadRemote', function (assert) {
         var res = loadRemote(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajaxresult.json', {},
         'GET', true);
-        deepEqual(res, ['foo', 'bar']);
+        assert.deepEqual(res, ['foo', 'bar']);
     });
 
-    QUnit.test('test event on CubicWeb', function() {
-        expect(1);
+    QUnit.test('test event on CubicWeb', function (assert) {
+        assert.expect(1);
         stop();
         var events = null;
         jQuery(CubicWeb).bind('server-response', function() {
@@ -239,7 +239,7 @@
         jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html')
         .addCallback(function() {
                 try {
-                    equal(events, 'CubicWeb');
+                    assert.equal(events, 'CubicWeb');
                 } finally {
                     start();
                 };
@@ -247,8 +247,8 @@
         );
     });
 
-    QUnit.test('test event on node', function() {
-        expect(3);
+    QUnit.test('test event on node', function (assert) {
+        assert.expect(3);
         stop();
         var nodes = [];
         jQuery('#qunit-fixture').bind('server-response', function() {
@@ -260,11 +260,11 @@
         jQuery('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html')
         .addCallback(function() {
                 try {
-                    equal(nodes.length, 2);
+                    assert.equal(nodes.length, 2);
                     // check that server-response event on CubicWeb is triggered
                     // only once and event server-response on node is triggered
-                    equal(nodes[0], 'CubicWeb');
-                    equal(nodes[1], 'node');
+                    assert.equal(nodes[0], 'CubicWeb');
+                    assert.equal(nodes[1], 'node');
                 } finally {
                     start();
                 };
--- a/web/test/jstests/test_htmlhelpers.js	Wed May 20 17:04:43 2015 +0200
+++ b/web/test/jstests/test_htmlhelpers.js	Wed May 20 15:45:43 2015 +0200
@@ -7,29 +7,29 @@
       }
     });
 
-    QUnit.test("test first selected", function() {
+    QUnit.test("test first selected", function (assert) {
         $('#theselect').append('<option value="foo">foo</option>' +
     			     '<option selected="selected" value="bar">bar</option>' +
     			     '<option value="baz">baz</option>' +
     			     '<option selected="selecetd"value="spam">spam</option>');
         var selected = firstSelected(document.getElementById("theselect"));
-        equal(selected.value, 'bar');
+        assert.equal(selected.value, 'bar');
     });
 
-    QUnit.test("test first selected 2", function() {
+    QUnit.test("test first selected 2", function (assert) {
         $('#theselect').append('<option value="foo">foo</option>' +
     			     '<option value="bar">bar</option>' +
     			     '<option value="baz">baz</option>' +
     			     '<option value="spam">spam</option>');
         var selected = firstSelected(document.getElementById("theselect"));
-        equal(selected, null);
+        assert.equal(selected, null);
     });
 
     QUnit.module("visibilty");
-    QUnit.test('toggleVisibility', function() {
+    QUnit.test('toggleVisibility', function (assert) {
         $('#qunit-fixture').append('<div id="foo"></div>');
         toggleVisibility('foo');
-        ok($('#foo').hasClass('hidden'), 'check hidden class is set');
+        assert.ok($('#foo').hasClass('hidden'), 'check hidden class is set');
     });
 
 });
--- a/web/test/jstests/test_utils.js	Wed May 20 17:04:43 2015 +0200
+++ b/web/test/jstests/test_utils.js	Wed May 20 15:45:43 2015 +0200
@@ -2,56 +2,56 @@
 
   QUnit.module("datetime");
 
-  QUnit.test("test full datetime", function() {
-      equal(cw.utils.toISOTimestamp(new Date(1986, 3, 18, 10, 30, 0, 0)),
+  QUnit.test("test full datetime", function (assert) {
+      assert.equal(cw.utils.toISOTimestamp(new Date(1986, 3, 18, 10, 30, 0, 0)),
 	     '1986-04-18 10:30:00');
   });
 
-  QUnit.test("test only date", function() {
-      equal(cw.utils.toISOTimestamp(new Date(1986, 3, 18)), '1986-04-18 00:00:00');
+  QUnit.test("test only date", function (assert) {
+      assert.equal(cw.utils.toISOTimestamp(new Date(1986, 3, 18)), '1986-04-18 00:00:00');
   });
 
-  QUnit.test("test null", function() {
-      equal(cw.utils.toISOTimestamp(null), null);
+  QUnit.test("test null", function (assert) {
+      assert.equal(cw.utils.toISOTimestamp(null), null);
   });
 
   QUnit.module("parsing");
-  QUnit.test("test basic number parsing", function() {
+  QUnit.test("test basic number parsing", function (assert) {
       var d = strptime('2008/08/08', '%Y/%m/%d');
-      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
+      assert.deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
       d = strptime('2008/8/8', '%Y/%m/%d');
-      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
+      assert.deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
       d = strptime('8/8/8', '%Y/%m/%d');
-      deepEqual(datetuple(d), [8, 8, 8, 0, 0]);
+      assert.deepEqual(datetuple(d), [8, 8, 8, 0, 0]);
       d = strptime('0/8/8', '%Y/%m/%d');
-      deepEqual(datetuple(d), [0, 8, 8, 0, 0]);
+      assert.deepEqual(datetuple(d), [0, 8, 8, 0, 0]);
       d = strptime('-10/8/8', '%Y/%m/%d');
-      deepEqual(datetuple(d), [-10, 8, 8, 0, 0]);
+      assert.deepEqual(datetuple(d), [-10, 8, 8, 0, 0]);
       d = strptime('-35000', '%Y');
-      deepEqual(datetuple(d), [-35000, 1, 1, 0, 0]);
+      assert.deepEqual(datetuple(d), [-35000, 1, 1, 0, 0]);
   });
 
-  QUnit.test("test custom format parsing", function() {
+  QUnit.test("test custom format parsing", function (assert) {
       var d = strptime('2008-08-08', '%Y-%m-%d');
-      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
+      assert.deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
       d = strptime('2008 - !  08: 08', '%Y - !  %m: %d');
-      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
+      assert.deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
       d = strptime('2008-08-08 12:14', '%Y-%m-%d %H:%M');
-      deepEqual(datetuple(d), [2008, 8, 8, 12, 14]);
+      assert.deepEqual(datetuple(d), [2008, 8, 8, 12, 14]);
       d = strptime('2008-08-08 1:14', '%Y-%m-%d %H:%M');
-      deepEqual(datetuple(d), [2008, 8, 8, 1, 14]);
+      assert.deepEqual(datetuple(d), [2008, 8, 8, 1, 14]);
       d = strptime('2008-08-08 01:14', '%Y-%m-%d %H:%M');
-      deepEqual(datetuple(d), [2008, 8, 8, 1, 14]);
+      assert.deepEqual(datetuple(d), [2008, 8, 8, 1, 14]);
   });
 
   QUnit.module("sliceList");
-  QUnit.test("test slicelist", function() {
+  QUnit.test("test slicelist", function (assert) {
       var list = ['a', 'b', 'c', 'd', 'e', 'f'];
-      deepEqual(cw.utils.sliceList(list, 2),  ['c', 'd', 'e', 'f']);
-      deepEqual(cw.utils.sliceList(list, 2, -2), ['c', 'd']);
-      deepEqual(cw.utils.sliceList(list, -3), ['d', 'e', 'f']);
-      deepEqual(cw.utils.sliceList(list, 0, -2), ['a', 'b', 'c', 'd']);
-      deepEqual(cw.utils.sliceList(list),  list);
+      assert.deepEqual(cw.utils.sliceList(list, 2),  ['c', 'd', 'e', 'f']);
+      assert.deepEqual(cw.utils.sliceList(list, 2, -2), ['c', 'd']);
+      assert.deepEqual(cw.utils.sliceList(list, -3), ['d', 'e', 'f']);
+      assert.deepEqual(cw.utils.sliceList(list, 0, -2), ['a', 'b', 'c', 'd']);
+      assert.deepEqual(cw.utils.sliceList(list),  list);
   });
 
   QUnit.module("formContents", {
@@ -60,7 +60,7 @@
     }
   });
   // XXX test fckeditor
-  QUnit.test("test formContents", function() {
+  QUnit.test("test formContents", function (assert) {
       $('#test-form').append('<input name="input-text" ' +
 			     'type="text" value="toto" />');
       $('#test-form').append('<textarea rows="10" cols="30" '+
@@ -83,7 +83,7 @@
 			     'value="one" />');
       $('#test-form').append('<input name="unchecked-choice" type="radio" ' +
 			     'value="two"/>');
-      deepEqual(cw.utils.formContents($('#test-form')[0]), [
+      assert.deepEqual(cw.utils.formContents($('#test-form')[0]), [
 	['input-text', 'mytextarea', 'choice', 'check', 'theselect'],
 	['toto', 'Hello World!', 'no', 'no', 'foo']
       ]);