diff --git a/package.json b/package.json index f6f0a58..b175359 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "http-server": "^0.11.1", "jshint": "^2.9.1", "steal": "^2.0.0", - "steal-qunit": "^1.0.1", + "steal-qunit": "^2.0.0", "steal-tools": "^1.1.2", "test-saucelabs": "0.0.6", "testee": "^0.9.0" diff --git a/test/link-to-test.js b/test/link-to-test.js index d5f3230..db35c33 100644 --- a/test/link-to-test.js +++ b/test/link-to-test.js @@ -2,18 +2,18 @@ var canRoute = require("can-route"); var QUnit = require("steal-qunit"); QUnit.module("can-route .linkTo",{ - setup: function(){ + beforeEach: function(assert) { canRoute.routes = {}; } }); -QUnit.test("linkTo", function () { +QUnit.test("linkTo", function(assert) { canRoute.routes = {}; canRoute.register("{foo}"); var res = canRoute.link("Hello", { foo: "bar", baz: "foo" }); - equal(res, "Hello"); + assert.equal(res, "Hello"); }); diff --git a/test/param-deparam-test.js b/test/param-deparam-test.js index 2b81e03..08ad93b 100644 --- a/test/param-deparam-test.js +++ b/test/param-deparam-test.js @@ -16,13 +16,13 @@ function getMsg(routes, input, method, output) { } QUnit.module("can-route .param and .deparam",{ - setup: function(){ + beforeEach: function(assert) { canRoute.defaultBinding = "hashchange"; canRoute.routes = {}; } }); -test("param / deparam / rule", function () { +QUnit.test("param / deparam / rule", function(assert) { var testCases = [ { routes: [], @@ -539,14 +539,14 @@ test("param / deparam / rule", function () { var actual = canRoute[method].apply(canRoute, input); if ("output" in assertion) { - QUnit.deepEqual(actual, assertion.output, + assert.deepEqual(actual, assertion.output, getMsg(testCase.routes, assertion.input, " --" + assertion.method + "-->", assertion.output) ); } if (assertion.symmetric) { var reverseMethod = method.indexOf("de") === 0 ? method.slice(2) : "de" + method; - QUnit.deepEqual(canRoute[reverseMethod].call(canRoute, actual), assertion.input, + assert.deepEqual(canRoute[reverseMethod].call(canRoute, actual), assertion.input, getMsg(testCase.routes, assertion.input, " <---> ", actual) ); } diff --git a/test/route-data-test.js b/test/route-data-test.js index e95823a..e6626f5 100644 --- a/test/route-data-test.js +++ b/test/route-data-test.js @@ -7,7 +7,7 @@ var mockRoute = require("./mock-route-binding"); require("can-observation"); QUnit.module("can-route.data", { - setup: function () { + beforeEach: function(assert) { canRoute._teardown(); canRoute.defaultBinding = "hashchange"; this.fixture = document.getElementById("qunit-fixture"); @@ -15,7 +15,7 @@ QUnit.module("can-route.data", { }); -test("can-route.data can be set to an element with a viewModel", function(){ +QUnit.test("can-route.data can be set to an element with a viewModel", function(assert) { var element = document.createElement("div"); var vm = new SimpleMap(); @@ -24,43 +24,45 @@ test("can-route.data can be set to an element with a viewModel", function(){ canRoute.data = element; - QUnit.equal(canRoute.data, vm, "works"); + assert.equal(canRoute.data, vm, "works"); }); -QUnit.asyncTest("Default map registers properties", function(){ - mockRoute.start(); +QUnit.test("Default map registers properties", function(assert) { + var ready = assert.async(); + mockRoute.start(); - canRoute.register("{type}/{id}"); + canRoute.register("{type}/{id}"); - canRoute._onStartComplete = function () { + canRoute._onStartComplete = function () { var after = mockRoute.hash.get(); - equal(after, "cat/5", "same URL"); - equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); - equal(canRoute.data.id, "5", "conflicts should be won by the URL"); - QUnit.start(); + assert.equal(after, "cat/5", "same URL"); + assert.equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); + assert.equal(canRoute.data.id, "5", "conflicts should be won by the URL"); + ready(); mockRoute.stop(); }; - mockRoute.hash.value = "#!cat/5"; - canRoute.start(); + mockRoute.hash.value = "#!cat/5"; + canRoute.start(); }); -QUnit.asyncTest("Property defaults influence the Type", function(){ - mockRoute.start(); +QUnit.test("Property defaults influence the Type", function(assert) { + var ready = assert.async(); + mockRoute.start(); - canRoute.register("{type}/{id}/{more}", { type: "dog", "id": 14, more: null }); + canRoute.register("{type}/{id}/{more}", { type: "dog", "id": 14, more: null }); - canRoute._onStartComplete = function () { + canRoute._onStartComplete = function () { var after = mockRoute.hash.get(); - equal(after, "cat/7/stuff", "same URL"); - equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); - deepEqual(canRoute.data.id, 7, "conflicts should be won by the URL"); - deepEqual(canRoute.data.more, "stuff", "null defaults are converted"); - QUnit.start(); + assert.equal(after, "cat/7/stuff", "same URL"); + assert.equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); + assert.deepEqual(canRoute.data.id, 7, "conflicts should be won by the URL"); + assert.deepEqual(canRoute.data.more, "stuff", "null defaults are converted"); + ready(); mockRoute.stop(); }; - mockRoute.hash.value = "#!cat/7/stuff"; - canRoute.start(); + mockRoute.hash.value = "#!cat/7/stuff"; + canRoute.start(); }); diff --git a/test/route-define-iframe-test.js b/test/route-define-iframe-test.js index a03d9fb..9967649 100644 --- a/test/route-define-iframe-test.js +++ b/test/route-define-iframe-test.js @@ -3,7 +3,7 @@ var QUnit = require("steal-qunit"); var canReflect = require("can-reflect"); QUnit.module("can-route with can-define/map/map in an iframe", { - setup: function () { + beforeEach: function() { canRoute._teardown(); canRoute.urlData = canRoute.bindings.hashchange; //canRoute.defaultBinding = "hashchange"; @@ -16,11 +16,11 @@ if (("onhashchange" in window)) { var teardownRouteTest; - var setupRouteTest = function(callback){ + var setupRouteTest = function(assert, callback){ var testarea = document.getElementById("qunit-fixture"); var iframe = document.createElement("iframe"); - stop(); + var done = assert.async(); window.routeTestReady = function(){ var args = canReflect.toArray(arguments); args.unshift(iframe); @@ -32,7 +32,7 @@ if (("onhashchange" in window)) { setTimeout(function(){ testarea.removeChild(iframe); setTimeout(function(){ - start(); + done(); },10); },1); }; @@ -40,14 +40,14 @@ if (("onhashchange" in window)) { if (typeof steal !== "undefined") { - test("listening to hashchange (#216, #124)", function () { + QUnit.test("listening to hashchange (#216, #124)", function(assert) { - setupRouteTest(function (iframe, iCanRoute) { + setupRouteTest(assert, function (iframe, iCanRoute) { - ok(!iCanRoute.data.bla, "Value not set yet"); + assert.ok(!iCanRoute.data.bla, "Value not set yet"); iCanRoute.bind("bla", function(){ - equal(iCanRoute.data.get("bla"), "blu", "Got route change event and value is as expected"); + assert.equal(iCanRoute.data.get("bla"), "blu", "Got route change event and value is as expected"); teardownRouteTest(); }); @@ -59,11 +59,11 @@ if (("onhashchange" in window)) { }); }); - test("updating the hash", function () { - setupRouteTest(function (iframe, iCanRoute, loc) { + QUnit.test("updating the hash", function(assert) { + setupRouteTest(assert, function (iframe, iCanRoute, loc) { iCanRoute._onStartComplete = function () { var after = loc.href.substr(loc.href.indexOf("#")); - equal(after, "#!bar/" + encodeURIComponent("\/")); + assert.equal(after, "#!bar/" + encodeURIComponent("\/")); teardownRouteTest(); }; @@ -78,8 +78,8 @@ if (("onhashchange" in window)) { }); }); - test("unsticky routes", function () { - setupRouteTest(function (iframe, iCanRoute, loc) { + QUnit.test("unsticky routes", function(assert) { + setupRouteTest(assert, function (iframe, iCanRoute, loc) { iCanRoute.register("{type}"); iCanRoute.register("{type}/{id}"); @@ -92,7 +92,7 @@ if (("onhashchange" in window)) { setTimeout(function () { var after = loc.href.substr(loc.href.indexOf("#")); - equal(after, "#!bar"); + assert.equal(after, "#!bar"); iCanRoute.attr({ type: "bar", id: "\/" @@ -105,7 +105,7 @@ if (("onhashchange" in window)) { var isMatch = after === "#!bar/" + encodeURIComponent("\/"); var isWaitingTooLong = new Date() - time > 5000; if (isMatch || isWaitingTooLong) { - equal(after, "#!bar/" + encodeURIComponent("\/"), "should go to type/id "+ (new Date() - time)); + assert.equal(after, "#!bar/" + encodeURIComponent("\/"), "should go to type/id "+ (new Date() - time)); teardownRouteTest(); } else { setTimeout(innerTimer, 30); diff --git a/test/route-define-test.js b/test/route-define-test.js index b077081..15f61b8 100644 --- a/test/route-define-test.js +++ b/test/route-define-test.js @@ -14,7 +14,7 @@ var mockRoute = require("./mock-route-binding"); require("can-observation"); QUnit.module("can/route with can-define/map/map", { - setup: function () { + beforeEach: function(assert) { canRoute.routes = {}; canRoute._teardown(); canRoute.urlData = canRoute.bindings.hashchange @@ -28,8 +28,8 @@ if (("onhashchange" in window)) { if (typeof steal !== "undefined") { - QUnit.test("canRoute.map: conflicting route values, hash should win (canjs/canjs#979)", function(){ - QUnit.stop(); + QUnit.test("canRoute.map: conflicting route values, hash should win (canjs/canjs#979)", function(assert) { + var done = assert.async(); mockRoute.start(); @@ -41,10 +41,10 @@ if (typeof steal !== "undefined") { canRoute._onStartComplete = function () { var after = mockRoute.hash.get(); - equal(after, "cat/5", "same URL"); - equal(appState.get("type"), "cat", "conflicts should be won by the URL"); - equal(appState.get("id"), "5", "conflicts should be won by the URL"); - QUnit.start(); + assert.equal(after, "cat/5", "same URL"); + assert.equal(appState.get("type"), "cat", "conflicts should be won by the URL"); + assert.equal(appState.get("id"), "5", "conflicts should be won by the URL"); + done(); mockRoute.stop(); }; @@ -52,8 +52,8 @@ if (typeof steal !== "undefined") { canRoute.start(); }); - QUnit.test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data (canjs/canjs#979)", function(){ - QUnit.stop(); + QUnit.test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data (canjs/canjs#979)", function(assert) { + var done = assert.async(); mockRoute.start(); canRoute.register("{type}/{id}"); @@ -63,23 +63,23 @@ if (typeof steal !== "undefined") { canRoute.data = appState; canRoute._onStartComplete = function () { - equal(mockRoute.hash.value, "cat/5§ion=home", "same URL"); - equal(appState.get("type"), "cat", "hash populates the appState"); - equal(appState.get("id"), "5", "hash populates the appState"); - equal(appState.get("section"), "home", "appState keeps its properties"); - ok(canRoute.data === appState, "canRoute.data is the same as appState"); + assert.equal(mockRoute.hash.value, "cat/5§ion=home", "same URL"); + assert.equal(appState.get("type"), "cat", "hash populates the appState"); + assert.equal(appState.get("id"), "5", "hash populates the appState"); + assert.equal(appState.get("section"), "home", "appState keeps its properties"); + assert.ok(canRoute.data === appState, "canRoute.data is the same as appState"); mockRoute.stop(); - QUnit.start(); + done(); }; mockRoute.hash.value = "#!cat/5"; // type and id get added ... this will call update url to add everything canRoute.start(); }); - test("sticky enough routes (canjs#36)", function () { + QUnit.test("sticky enough routes (canjs#36)", function(assert) { - QUnit.stop(); + var done = assert.async(); mockRoute.start(); canRoute.register("active"); @@ -91,95 +91,99 @@ if (typeof steal !== "undefined") { setTimeout(function () { var after = mockRoute.hash.get(); - equal(after, "active"); + assert.equal(after, "active"); mockRoute.stop(); - QUnit.start(); + done(); }, 30); }); - QUnit.asyncTest("canRoute.current is live-bindable (#1156)", function () { - mockRoute.start(); + QUnit.test("canRoute.current is live-bindable (#1156)", function(assert) { + var ready = assert.async(); + mockRoute.start(); - canRoute.start(); - var isOnTestPage = new Observation(function isCurrent(){ + canRoute.start(); + var isOnTestPage = new Observation(function isCurrent(){ return canRoute.isCurrent({page: "test"}); }); - canReflect.onValue(isOnTestPage, function isCurrentChanged(){ + canReflect.onValue(isOnTestPage, function isCurrentChanged(){ // unbind now because isCurrent depends on urlData isOnTestPage.off(); mockRoute.stop(); - QUnit.start(); + ready(); }); - equal(canRoute.isCurrent({page: "test"}), false, "initially not on test page") - setTimeout(function(){ + assert.equal(canRoute.isCurrent({page: "test"}), false, "initially not on test page") + setTimeout(function(){ canRoute.data.set("page","test"); },20); - }); + }); - QUnit.asyncTest("can.compute.read should not call canRoute (#1154)", function () { - mockRoute.start(); - canRoute.attr("page","test"); - canRoute.start(); + QUnit.test("can.compute.read should not call canRoute (#1154)", function(assert) { + var ready = assert.async(); + mockRoute.start(); + canRoute.attr("page","test"); + canRoute.start(); - var val = stacheKey.read({route: canRoute},stacheKey.reads("route")).value; + var val = stacheKey.read({route: canRoute},stacheKey.reads("route")).value; - setTimeout(function(){ - equal(val,canRoute,"read correctly"); + setTimeout(function(){ + assert.equal(val,canRoute,"read correctly"); mockRoute.stop(); - QUnit.start(); + ready(); },1); - }); + }); - QUnit.asyncTest("routes should deep clean", function() { - expect(2); + QUnit.test("routes should deep clean", function(assert) { + var ready = assert.async(); + assert.expect(2); - mockRoute.start(); + mockRoute.start(); - var hash1 = canRoute.url({ + var hash1 = canRoute.url({ panelA: { name: "fruit", id: 15, show: true } }); - var hash2 = canRoute.url({ + var hash2 = canRoute.url({ panelA: { name: "fruit", id: 20, read: false } }); - mockRoute.hash.value = hash1; - mockRoute.hash.value = hash2; + mockRoute.hash.value = hash1; + mockRoute.hash.value = hash2; - canRoute._onStartComplete = function() { - equal(canRoute.data.get("panelA").id, 20, "id should change"); - equal(canRoute.data.get("panelA").show, undefined, "show should be removed"); + canRoute._onStartComplete = function() { + assert.equal(canRoute.data.get("panelA").id, 20, "id should change"); + assert.equal(canRoute.data.get("panelA").show, undefined, "show should be removed"); mockRoute.stop(); - QUnit.start(); + ready(); }; - canRoute.start(); - }); + canRoute.start(); + }); - QUnit.asyncTest("updating bound DefineMap causes single update with a coerced string value", function() { - expect(1); + QUnit.test("updating bound DefineMap causes single update with a coerced string value", function(assert) { + var ready = assert.async(); + assert.expect(1); - canRoute.start(); - var MyMap = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); - var appVM = new MyMap(); + canRoute.start(); + var MyMap = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); + var appVM = new MyMap(); - canRoute.data = appVM; + canRoute.data = appVM; - canRoute._onStartComplete = function(){ + canRoute._onStartComplete = function(){ appVM.on("action", function(ev, newVal) { - strictEqual(newVal, "10"); + assert.strictEqual(newVal, "10"); }); appVM.set("action", 10); @@ -187,14 +191,14 @@ if (typeof steal !== "undefined") { // check after 30ms to see that we only have a single call setTimeout(function() { mockRoute.stop(); - QUnit.start(); + ready(); }, 5); }; - canRoute.start(); - }); + canRoute.start(); + }); - test("hash doesn't update to itself with a !", function() { - stop(); + QUnit.test("hash doesn't update to itself with a !", function(assert) { + var done = assert.async(); window.routeTestReady = function (iCanRoute, loc) { iCanRoute.start(); @@ -204,9 +208,9 @@ if (typeof steal !== "undefined") { setTimeout(function() { var counter = 0; try { - equal(loc.hash, "#!foo"); + assert.equal(loc.hash, "#!foo"); } catch(e) { - start(); + done(); throw e; } @@ -217,10 +221,10 @@ if (typeof steal !== "undefined") { loc.hash = "bar"; setTimeout(function() { try { - equal(loc.hash, "#bar"); - equal(counter, 1); //sanity check -- bindings only ran once before this change. + assert.equal(loc.hash, "#bar"); + assert.equal(counter, 1); //sanity check -- bindings only ran once before this change. } finally { - start(); + done(); } }, 100); }, 100); @@ -233,7 +237,7 @@ if (typeof steal !== "undefined") { } -test("escaping periods", function () { +QUnit.test("escaping periods", function(assert) { canRoute.routes = {}; canRoute.register("{page}\\.html", { @@ -241,11 +245,11 @@ test("escaping periods", function () { }); var obj = canRoute.deparam("can.Control.html"); - deepEqual(obj, { + assert.deepEqual(obj, { page: "can.Control" }); - equal(canRoute.param({ + assert.equal(canRoute.param({ page: "can.Control" }), "can.Control.html"); @@ -253,7 +257,7 @@ test("escaping periods", function () { if (typeof require !== "undefined") { - test("correct stringing", function () { + QUnit.test("correct stringing", function(assert) { mockRoute.start(); canRoute.routes = {}; @@ -265,7 +269,7 @@ if (typeof require !== "undefined") { array: [1, true, "hello"] }); - QUnit.deepEqual(canRoute.attr(),{ + assert.deepEqual(canRoute.attr(),{ number: "1", bool: "true", string: "hello", @@ -284,7 +288,7 @@ if (typeof require !== "undefined") { } }); - QUnit.deepEqual(canRoute.attr(), { + assert.deepEqual(canRoute.attr(), { number: "1", bool: "true", string: "hello", @@ -306,7 +310,7 @@ if (typeof require !== "undefined") { sort_by_name: true }); - propEqual(canRoute.attr(), { + assert.propEqual(canRoute.attr(), { type: "page", id: "10", sort_by_name: "true" @@ -316,12 +320,12 @@ if (typeof require !== "undefined") { } -test("on/off binding", function () { +QUnit.test("on/off binding", function(assert) { canRoute.routes = {}; - expect(1) + assert.expect(1) canRoute.on("foo", function () { - ok(true, "foo called"); + assert.ok(true, "foo called"); canRoute.off("foo"); @@ -331,9 +335,9 @@ test("on/off binding", function () { canRoute.attr("foo", "bar"); }); -test("two way binding canRoute.map with DefineMap instance", function(){ - expect(2); - stop(); +QUnit.test("two way binding canRoute.map with DefineMap instance", function(assert) { + assert.expect(2); + var done = assert.async(); mockRoute.start(); var AppState = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); @@ -346,21 +350,21 @@ test("two way binding canRoute.map with DefineMap instance", function(){ canRoute.serializedCompute.bind("change", function(){ - equal(canRoute.attr("name"), "Brian", "appState is bound to canRoute"); + assert.equal(canRoute.attr("name"), "Brian", "appState is bound to canRoute"); canRoute.serializedCompute.unbind("change"); appState.name = undefined; setTimeout(function(){ - equal( mockRoute.hash.get(), ""); + assert.equal( mockRoute.hash.get(), ""); mockRoute.stop(); - start(); + done(); },20); }); appState.set("name", "Brian"); }); -test(".url with merge=true", function(){ +QUnit.test(".url with merge=true", function(assert) { mockRoute.start() var AppState = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); @@ -370,17 +374,17 @@ test(".url with merge=true", function(){ canRoute.data = appState; canRoute.start(); - QUnit.stop(); + var done = assert.async(); appState.set("foo", "bar"); // TODO: expose a way to know when the url has changed. setTimeout(function(){ var result = canRoute.url({page: "recipe", id: 5}, true); - QUnit.equal(result, "#!&foo=bar&page=recipe&id=5"); + assert.equal(result, "#!&foo=bar&page=recipe&id=5"); mockRoute.stop(); - QUnit.start(); + done(); },20); }); @@ -391,7 +395,7 @@ test(".url with merge=true", function(){ } -test("param with whitespace in interpolated string (#45)", function () { +QUnit.test("param with whitespace in interpolated string (#45)", function(assert) { canRoute.routes = {}; canRoute.register("{ page }", { page: "index" @@ -400,7 +404,7 @@ test("param with whitespace in interpolated string (#45)", function () { var res = canRoute.param({ page: "index" }); - equal(res, "") + assert.equal(res, "") canRoute.register("pages/{ p1 }/{ p2 }/{ p3 }", { p1: "index", @@ -413,18 +417,18 @@ test("param with whitespace in interpolated string (#45)", function () { p2: "foo", p3: "bar" }); - equal(res, "pages///") + assert.equal(res, "pages///") res = canRoute.param({ p1: "index", p2: "baz", p3: "bar" }); - equal(res, "pages//baz/") + assert.equal(res, "pages//baz/") }); -test("triggers __url event anytime a there's a change to individual properties", function(){ +QUnit.test("triggers __url event anytime a there's a change to individual properties", function(assert) { mockRoute.start(); var AppState = DefineMap.extend({seal: false},{"*": "stringOrObservable", page: "string", section: "string"}); @@ -434,7 +438,7 @@ test("triggers __url event anytime a there's a change to individual properties", canRoute.register("{page}"); canRoute.register("{page}/{section}"); - QUnit.stop(); + var done = assert.async(); canRoute.start(); var matchedCount = 0; @@ -447,10 +451,10 @@ test("triggers __url event anytime a there's a change to individual properties", }, 3: function(){ // 1st call is going from undefined to empty string - equal(matchedCount, 3, "calls __url event every time a property is changed"); + assert.equal(matchedCount, 3, "calls __url event every time a property is changed"); mockRoute.stop(); - QUnit.start(); + done(); } } canRoute.on("__url", function updateMatchedCount() { @@ -466,27 +470,28 @@ test("triggers __url event anytime a there's a change to individual properties", }); -QUnit.asyncTest("updating unserialized prop on bound DefineMap causes single update without a coerced string value", function() { - expect(1); - canRoute.routes = {}; - mockRoute.start(); +QUnit.test("updating unserialized prop on bound DefineMap causes single update without a coerced string value", function(assert) { + var ready = assert.async(); + assert.expect(1); + canRoute.routes = {}; + mockRoute.start(); - var appVM = new (DefineMap.extend({ + var appVM = new (DefineMap.extend({ action: {serialize: false, type: "*"} }))(); - canRoute.data = appVM; - canRoute.start(); + canRoute.data = appVM; + canRoute.start(); - appVM.bind("action", function(ev, newVal) { - equal(typeof newVal, "function"); + appVM.bind("action", function(ev, newVal) { + assert.equal(typeof newVal, "function"); }); - appVM.set("action", function() {}); + appVM.set("action", function() {}); - // check after 30ms to see that we only have a single call - setTimeout(function() { + // check after 30ms to see that we only have a single call + setTimeout(function() { mockRoute.stop(); - QUnit.start(); + ready(); }, 5); }); diff --git a/test/route-map-test.js b/test/route-map-test.js index f209199..9afe9b1 100644 --- a/test/route-map-test.js +++ b/test/route-map-test.js @@ -6,7 +6,7 @@ var canReflect = require("can-reflect"); QUnit.module("can/route with can-map", { - setup: function () { + beforeEach: function(assert) { canRoute._teardown(); canRoute.defaultBinding = "hashchange"; this.fixture = document.getElementById("qunit-fixture"); @@ -16,11 +16,11 @@ QUnit.module("can/route with can-map", { if (("onhashchange" in window)) { var teardownRouteTest; -var setupRouteTest = function(callback){ +var setupRouteTest = function(assert, callback){ var testarea = document.getElementById("qunit-fixture"); var iframe = document.createElement("iframe"); - stop(); + var done = assert.async(); window.routeTestReady = function(iCanRoute){ var args = canReflect.toArray(arguments) args.unshift(iframe); @@ -32,7 +32,7 @@ var setupRouteTest = function(callback){ setTimeout(function(){ testarea.removeChild(iframe); setTimeout(function(){ - start(); + done(); },10); },1); }; @@ -40,14 +40,14 @@ var setupRouteTest = function(callback){ if (typeof steal !== "undefined") { - test("listening to hashchange (#216, #124)", function () { + QUnit.test("listening to hashchange (#216, #124)", function(assert) { - setupRouteTest(function (iframe, iCanRoute) { + setupRouteTest(assert, function (iframe, iCanRoute) { - ok(!iCanRoute.attr("bla"), "Value not set yet"); + assert.ok(!iCanRoute.attr("bla"), "Value not set yet"); iCanRoute.bind("change", function () { - equal(iCanRoute.attr("bla"), "blu", "Got route change event and value is as expected"); + assert.equal(iCanRoute.attr("bla"), "blu", "Got route change event and value is as expected"); teardownRouteTest(); }); @@ -61,23 +61,23 @@ if (typeof steal !== "undefined") { }); - test("removing things from the hash", function () { + QUnit.test("removing things from the hash", function(assert) { - setupRouteTest(function (iframe, iCanRoute, loc) { + setupRouteTest(assert, function (iframe, iCanRoute, loc) { // CanJS's build was failing on this test. // This code is to make sure we can more information on why the build // failed. var outerChangeCalled = false; setTimeout(function(){ if(outerChangeCalled === false) { - QUnit.ok(outerChangeCalled, "no outer change called"); + assert.ok(outerChangeCalled, "no outer change called"); teardownRouteTest(); } },60000); iCanRoute.bind("change", function change1() { outerChangeCalled = true; - equal(iCanRoute.attr("foo"), "bar", "expected value"); + assert.equal(iCanRoute.attr("foo"), "bar", "expected value"); iCanRoute.unbind("change"); var changeFired = false, @@ -85,15 +85,15 @@ if (typeof steal !== "undefined") { iCanRoute.bind("change", function change2(ev, prop){ changeFired = true; - equal(iCanRoute.attr("personId"), "3", "personId"); - equal(iCanRoute.attr("foo"), undefined, "unexpected value"); + assert.equal(iCanRoute.attr("personId"), "3", "personId"); + assert.equal(iCanRoute.attr("foo"), undefined, "unexpected value"); iCanRoute.unbind("change"); if (prop === "personId") { tearDown = true; teardownRouteTest(); } else { - QUnit.equal(prop, "foo", "removed foo"); + assert.equal(prop, "foo", "removed foo"); } }); @@ -102,8 +102,8 @@ if (typeof steal !== "undefined") { // failed. setTimeout(function(){ if(tearDown === false) { - QUnit.ok(changeFired, "changed was fired"); - QUnit.ok(false, "no personId change"); + assert.ok(changeFired, "changed was fired"); + assert.ok(false, "no personId change"); teardownRouteTest(); } },60000); @@ -124,8 +124,8 @@ if (typeof steal !== "undefined") { }); }); - test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data", function(){ - setupRouteTest(function (iframe, iCanRoute, loc, win) { + QUnit.test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data", function(assert) { + setupRouteTest(assert, function (iframe, iCanRoute, loc, win) { iCanRoute.register("{type}/{id}"); var AppState = win.CanMap.extend(); @@ -135,11 +135,11 @@ if (typeof steal !== "undefined") { iCanRoute._onStartComplete = function () { var after = loc.href.substr(loc.href.indexOf("#")); - equal(after, "#!cat/5§ion=home", "same URL"); - equal(appState.attr("type"), "cat", "hash populates the appState"); - equal(appState.attr("id"), "5", "hash populates the appState"); - equal(appState.attr("section"), "home", "appState keeps its properties"); - ok(iCanRoute.data === appState, "canRoute.data is the same as appState"); + assert.equal(after, "#!cat/5§ion=home", "same URL"); + assert.equal(appState.attr("type"), "cat", "hash populates the appState"); + assert.equal(appState.attr("id"), "5", "hash populates the appState"); + assert.equal(appState.attr("section"), "home", "appState keeps its properties"); + assert.ok(iCanRoute.data === appState, "canRoute.data is the same as appState"); teardownRouteTest(); @@ -150,11 +150,11 @@ if (typeof steal !== "undefined") { }); }); - test("updating the hash", function () { - setupRouteTest(function (iframe, iCanRoute, loc) { + QUnit.test("updating the hash", function(assert) { + setupRouteTest(assert, function (iframe, iCanRoute, loc) { iCanRoute._onStartComplete = function () { var after = loc.href.substr(loc.href.indexOf("#")); - equal(after, "#!bar/" + encodeURIComponent("\/")); + assert.equal(after, "#!bar/" + encodeURIComponent("\/")); teardownRouteTest(); }; @@ -168,9 +168,9 @@ if (typeof steal !== "undefined") { }); }); - test("sticky enough routes", function () { + QUnit.test("sticky enough routes", function(assert) { - setupRouteTest(function (iframe, iCanRoute, loc) { + setupRouteTest(assert, function (iframe, iCanRoute, loc) { iCanRoute.start() iCanRoute.register("active"); @@ -181,7 +181,7 @@ if (typeof steal !== "undefined") { setTimeout(function () { var after = loc.href.substr(loc.href.indexOf("#")); - equal(after, "#!active"); + assert.equal(after, "#!active"); teardownRouteTest(); @@ -189,17 +189,17 @@ if (typeof steal !== "undefined") { }); }); - test("updating bound SimpleMap causes single update with a coerced string value", function() { - expect(1); + QUnit.test("updating bound SimpleMap causes single update with a coerced string value", function(assert) { + assert.expect(1); - setupRouteTest(function (iframe, route, loc, win) { + setupRouteTest(assert, function (iframe, route, loc, win) { var appVM = new win.CanMap(); route.data = appVM; route.start(); appVM.bind("action", function(ev, newVal) { - strictEqual(newVal, "10"); + assert.strictEqual(newVal, "10"); }); appVM.attr("action", 10); @@ -211,8 +211,8 @@ if (typeof steal !== "undefined") { }); }); - test("hash doesn't update to itself with a !", function() { - stop(); + QUnit.test("hash doesn't update to itself with a !", function(assert) { + var done = assert.async(); window.routeTestReady = function (iCanRoute, loc) { iCanRoute.start(); @@ -222,9 +222,9 @@ if (typeof steal !== "undefined") { setTimeout(function() { var counter = 0; try { - equal(loc.hash, "#!foo"); + assert.equal(loc.hash, "#!foo"); } catch(e) { - start(); + done(); throw e; } @@ -235,10 +235,10 @@ if (typeof steal !== "undefined") { loc.hash = "bar"; setTimeout(function() { try { - equal(loc.hash, "#bar"); - equal(counter, 1); //sanity check -- bindings only ran once before this change. + assert.equal(loc.hash, "#bar"); + assert.equal(counter, 1); //sanity check -- bindings only ran once before this change. } finally { - start(); + done(); } }, 100); }, 100); @@ -251,7 +251,7 @@ if (typeof steal !== "undefined") { } -test("escaping periods", function () { +QUnit.test("escaping periods", function(assert) { canRoute.routes = {}; canRoute.register("{page}\\.html", { @@ -259,11 +259,11 @@ test("escaping periods", function () { }); var obj = canRoute.deparam("can.Control.html"); - deepEqual(obj, { + assert.deepEqual(obj, { page: "can.Control" }); - equal(canRoute.param({ + assert.equal(canRoute.param({ page: "can.Control" }), "can.Control.html"); @@ -271,12 +271,12 @@ test("escaping periods", function () { if (typeof require === "undefined") { - test("correct stringing", function () { - setupRouteTest(function(iframe, route) { + QUnit.test("correct stringing", function(assert) { + setupRouteTest(assert, function(iframe, route) { route.routes = {}; route.attr("number", 1); - propEqual(route.attr(), { + assert.propEqual(route.attr(), { "number": "1" }); @@ -284,21 +284,21 @@ if (typeof require === "undefined") { bool: true }, true); - propEqual(route.attr(), { + assert.propEqual(route.attr(), { "bool": "true" }); route.attr({ string: "hello" }, true); - propEqual(route.attr(), { + assert.propEqual(route.attr(), { "string": "hello" }); route.attr({ array: [1, true, "hello"] }, true); - propEqual(route.attr(), { + assert.propEqual(route.attr(), { "array": ["1", "true", "hello"] }); @@ -313,7 +313,7 @@ if (typeof require === "undefined") { } }, true); - propEqual(route.attr(), { + assert.propEqual(route.attr(), { number: "1", bool: "true", string: "hello", @@ -333,7 +333,7 @@ if (typeof require === "undefined") { sort_by_name: true }, true); - propEqual(route.attr(), { + assert.propEqual(route.attr(), { type: "page", id: "10", sort_by_name: "true" @@ -345,28 +345,28 @@ if (typeof require === "undefined") { } -test("Calling attr with an object should not stringify object (#197)", function () { - setupRouteTest(function (iframe, iCanRoute, loc, win) { +QUnit.test("Calling attr with an object should not stringify object (#197)", function(assert) { + setupRouteTest(assert, function (iframe, iCanRoute, loc, win) { var app = new win.CanMap({}); app.define = { foo: { serialize: false } }; app.attr("foo", true); - equal(app.attr("foo"), true, "not route data - .attr(\"foo\", ...) works"); + assert.equal(app.attr("foo"), true, "not route data - .attr(\"foo\", ...) works"); app.attr({ foo: false }); - equal(app.attr("foo"), false, "not route data - .attr({\"foo\": ...}) works"); + assert.equal(app.attr("foo"), false, "not route data - .attr({\"foo\": ...}) works"); iCanRoute.data = app; app.attr("foo", true); - equal(app.attr("foo"), true, "route data - .attr(\"foo\", ...) works"); + assert.equal(app.attr("foo"), true, "route data - .attr(\"foo\", ...) works"); app.attr({ foo: false }); - equal(app.attr("foo"), false, "route data - .attr({\"foo\": ...}) works"); + assert.equal(app.attr("foo"), false, "route data - .attr({\"foo\": ...}) works"); teardownRouteTest(); }); diff --git a/test/route-observability-test.js b/test/route-observability-test.js index 65e1afa..88dad70 100644 --- a/test/route-observability-test.js +++ b/test/route-observability-test.js @@ -4,16 +4,16 @@ var mockRoute = require("./mock-route-binding"); var DefineMap = require("can-define/map/"); QUnit.module("can-route observablility",{ - setup: function(){ + beforeEach: function(assert) { canRoute.routes = {}; } }); -QUnit.test("on/off binding", function () { +QUnit.test("on/off binding", function(assert) { canRoute.routes = {}; - expect(1); + assert.expect(1); canRoute.on("foo", function () { - ok(true, "foo called"); + assert.ok(true, "foo called"); canRoute.off("foo"); @@ -25,10 +25,10 @@ QUnit.test("on/off binding", function () { //var queues = require("can-queues"); //queues.log("flush"); -test("currentRule() compute", function() { +QUnit.test("currentRule() compute", function(assert) { mockRoute.start(); - QUnit.stop(); + var done = assert.async(); var AppState = DefineMap.extend({ seal: false @@ -43,14 +43,14 @@ test("currentRule() compute", function() { canRoute.register("{type}/{subtype}"); canRoute.start(); - equal(appState.route, undefined, "should not set route on appState"); - equal(canRoute.currentRule(), "{type}", "should set route.currentRule property"); + assert.equal(appState.route, undefined, "should not set route on appState"); + assert.equal(canRoute.currentRule(), "{type}", "should set route.currentRule property"); appState.subtype = "bar"; var check = function(){ if(canRoute.currentRule() === "{type}/{subtype}") { - QUnit.ok(true, "moved to right route"); + assert.ok(true, "moved to right route"); mockRoute.stop(); - start(); + done(); } else { setTimeout(check, 20); } diff --git a/test/route-observe-test.js b/test/route-observe-test.js index 493be71..e85b0a2 100644 --- a/test/route-observe-test.js +++ b/test/route-observe-test.js @@ -5,15 +5,15 @@ var mockRoute = require("./mock-route-binding"); var canReflect = require("can-reflect"); QUnit.module("can-route observe",{ - setup: function(){ + beforeEach: function(assert) { canRoute.routes = {}; } }); -QUnit.test("two way binding canRoute.map with a can-observe instance", function(){ +QUnit.test("two way binding canRoute.map with a can-observe instance", function(assert) { - expect(3); - stop(); + assert.expect(3); + var done = assert.async(); mockRoute.start(); var AppState = observe.Object.extend("AppState",{},{}); @@ -23,14 +23,14 @@ QUnit.test("two way binding canRoute.map with a can-observe instance", function( canRoute.start(); canReflect.onValue( mockRoute.hash, function handler1(newVal){ - QUnit.equal(newVal, "#&name=Brian", "updated hash"); + assert.equal(newVal, "#&name=Brian", "updated hash"); canReflect.offValue( mockRoute.hash, handler1); - QUnit.equal(canRoute.data.name, "Brian", "appState is bound to canRoute"); + assert.equal(canRoute.data.name, "Brian", "appState is bound to canRoute"); canReflect.onValue( mockRoute.hash, function handler2(newVal){ - equal( newVal, "#"); + assert.equal( newVal, "#"); mockRoute.stop(); - start(); + done(); }); delete appState.name; diff --git a/test/route-register-test.js b/test/route-register-test.js index 6adebf6..e9d29e1 100644 --- a/test/route-register-test.js +++ b/test/route-register-test.js @@ -3,39 +3,39 @@ var QUnit = require("steal-qunit"); var testHelpers = require("can-test-helpers"); QUnit.module("can-route .register", { - setup: function(){ + beforeEach: function(assert) { canRoute.routes = {}; } }); -testHelpers.dev.devOnlyTest("should warn when two routes have same map properties", function () { +testHelpers.dev.devOnlyTest("should warn when two routes have same map properties", function (assert) { var teardown = testHelpers.dev.willWarn(/two routes were registered with matching keys/); canRoute.register("{page}/{subpage}"); canRoute.register("foo/{page}/{subpage}"); - equal(teardown(), 1); + assert.equal(teardown(), 1); }); -testHelpers.dev.devOnlyTest("should warn when two routes have same map properties - including defaults", function () { +testHelpers.dev.devOnlyTest("should warn when two routes have same map properties - including defaults", function (assert) { var teardown = testHelpers.dev.willWarn(/two routes were registered with matching keys/); canRoute.register("foo/{page}/{subpage}"); canRoute.register("{page}/{subpage}"); - equal(teardown(), 1); + assert.equal(teardown(), 1); }); -testHelpers.dev.devOnlyTest("should not warn when two routes have same map properties - but different defaults(#36)", function () { +testHelpers.dev.devOnlyTest("should not warn when two routes have same map properties - but different defaults(#36)", function (assert) { var teardown = testHelpers.dev.willWarn(/two routes were registered with matching keys/); canRoute.register("login", { "page": "auth", "subpage": "login" }); canRoute.register("signup", { "page": "auth", "subpage": "signup" }); - equal(teardown(), 0); + assert.equal(teardown(), 0); }); -testHelpers.dev.devOnlyTest("should not be display warning for matching keys when the routes do not match (#99)", function () { +testHelpers.dev.devOnlyTest("should not be display warning for matching keys when the routes do not match (#99)", function (assert) { var expectedWarningText = "two routes were registered with matching keys:\n" + "\t(1) route.register(\"login\", {\"page\":\"auth\"})\n" + "\t(2) route.register(\"signup\", {\"page\":\"auth\"})\n" + @@ -55,5 +55,5 @@ testHelpers.dev.devOnlyTest("should not be display warning for matching keys whe canRoute.register("login3", { "page":"auth3" }); canRoute.register("login3", { "page":"auth3" }); - equal(teardown(), 1); + assert.equal(teardown(), 1); }); diff --git a/test/route-stop-test.js b/test/route-stop-test.js index 0078c95..6455ece 100644 --- a/test/route-stop-test.js +++ b/test/route-stop-test.js @@ -6,15 +6,15 @@ var mock = require("./mock-route-binding"); require("can-observation"); QUnit.module("can-route.stop", { - setup: function () { + beforeEach: function(assert) { mock.stop(); canRoute.defaultBinding = "mock"; this.fixture = document.getElementById("qunit-fixture"); } }); -test("Calling route.stop() tears down bindings", function(){ - QUnit.stop(); +QUnit.test("Calling route.stop() tears down bindings", function(assert) { + var done = assert.async(); mock.start(); canRoute.routes = {}; @@ -25,7 +25,7 @@ test("Calling route.stop() tears down bindings", function(){ var hash = mock.hash; setTimeout(function(){ - QUnit.equal(hash.get(), "home", "set to home"); + assert.equal(hash.get(), "home", "set to home"); canRoute.stop(); canRoute.data = new SimpleMap({page: "home"}); @@ -34,8 +34,8 @@ test("Calling route.stop() tears down bindings", function(){ canRoute.data.set("page", "cart"); setTimeout(function(){ - QUnit.equal(hash.get(), "cart", "now it is the cart"); - QUnit.start(); + assert.equal(hash.get(), "cart", "now it is the cart"); + done(); }, 30); }, 30); }); diff --git a/test/url-test.js b/test/url-test.js index a114e6f..9d73373 100644 --- a/test/url-test.js +++ b/test/url-test.js @@ -6,13 +6,13 @@ var RouteMock = require("can-route-mock"); var canReflect = require("can-reflect"); QUnit.module("can-route .url",{ - setup: function(){ + beforeEach: function(assert) { canRoute.routes = {}; } }); -test(".url with merge=true (#16)", function(){ - QUnit.stop(); +QUnit.test(".url with merge=true (#16)", function(assert) { + var done = assert.async(); var oldUsing = canRoute.urlData; var mock = canRoute.urlData = new RouteMock(); var AppState = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); @@ -25,15 +25,15 @@ test(".url with merge=true (#16)", function(){ appState.update({"foo": "bar",page: "recipe", id: 5}); canReflect.onValue(mock,function(){ - QUnit.equal(canRoute.url({}, true), "#!&foo=bar&page=recipe&id=5", "empty"); - QUnit.ok(canRoute.url({page: "recipe"}, true), "page:recipe is true"); + assert.equal(canRoute.url({}, true), "#!&foo=bar&page=recipe&id=5", "empty"); + assert.ok(canRoute.url({page: "recipe"}, true), "page:recipe is true"); - QUnit.ok(canRoute.url({page: "recipe", id: 5}, true), "number to string works"); - QUnit.ok(canRoute.url({page: "recipe", id: 6}, true), "not all equal"); + assert.ok(canRoute.url({page: "recipe", id: 5}, true), "number to string works"); + assert.ok(canRoute.url({page: "recipe", id: 6}, true), "not all equal"); setTimeout(function(){ canRoute.urlData = oldUsing; - QUnit.start(); + done(); },20); });