Skip to content

Commit

Permalink
Merge pull request #54 from canjs/landscaper/qunit2
Browse files Browse the repository at this point in the history
Landscaper: QUnit2 upgrade
  • Loading branch information
cherifGsoul committed May 24, 2019
2 parents 9c94583 + 33cd0cb commit 702b6b5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 77 deletions.
120 changes: 60 additions & 60 deletions can-globals-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,93 +22,93 @@ function loop(fn, count, ctx){

QUnit.module('can-globals/can-globals-proto');

QUnit.test('getKeyValue of undefined property', function() {
QUnit.test('getKeyValue of undefined property', function(assert) {
globals = new Globals();
globals.getKeyValue('test');
ok(true);
assert.ok(true);
});

QUnit.test('setKeyValue of undefined property', function() {
QUnit.test('setKeyValue of undefined property', function(assert) {
globals = new Globals();
globals.setKeyValue('foo', 'bar');
equal(globals.getKeyValue('foo'), 'bar');
assert.equal(globals.getKeyValue('foo'), 'bar');
});

QUnit.test('deleteKeyValue of undefined property', function() {
QUnit.test('deleteKeyValue of undefined property', function(assert) {
globals = new Globals();
globals.deleteKeyValue('test');
ok(true);
assert.ok(true);
});

QUnit.test('onKeyValue of undefined property', function() {
QUnit.test('onKeyValue of undefined property', function(assert) {
globals = new Globals();
globals.onKeyValue('test', function() {});
ok(true);
assert.ok(true);
globals.offKeyValue('test');
});

QUnit.test('offKeyValue of undefined property', function() {
QUnit.test('offKeyValue of undefined property', function(assert) {
globals = new Globals();
globals.offKeyValue('test', function() {});
ok(true);
assert.ok(true);
});

QUnit.test('makeExport of undefined property', function() {
QUnit.test('makeExport of undefined property', function(assert) {
globals = new Globals();
globals.makeExport('test');
ok(true);
assert.ok(true);
});

QUnit.test('define with cache disabled', function() {
QUnit.test('define with cache disabled', function(assert) {
var getter = spy('bar');
globals = new Globals();
globals.define('foo', getter, false);
loop(function(){
globals.getKeyValue('foo');
}, 5);
equal(getter.callCount, 5);
assert.equal(getter.callCount, 5);
});

QUnit.test('define with cache enabled', function() {
QUnit.test('define with cache enabled', function(assert) {
var getter = spy('bar');
globals = new Globals();
globals.define('foo', getter);
loop(function(){
globals.getKeyValue('foo');
}, 5);
equal(getter.callCount, 1);
assert.equal(getter.callCount, 1);
});

QUnit.test('define and get a new property', function() {
QUnit.test('define and get a new property', function(assert) {
globals = new Globals();
globals.define('test', 'default');
equal(globals.getKeyValue('test'), 'default');
assert.equal(globals.getKeyValue('test'), 'default');
});

QUnit.test('setKeyValue of existing property to string', function() {
QUnit.test('setKeyValue of existing property to string', function(assert) {
globals = new Globals();
globals.define('test', 'default');
globals.setKeyValue('test', 'updated');
equal(globals.getKeyValue('test'), 'updated');
assert.equal(globals.getKeyValue('test'), 'updated');
});

QUnit.test('setKeyValue of existing property to undefined', function() {
QUnit.test('setKeyValue of existing property to undefined', function(assert) {
globals = new Globals();
globals.define('test', 'default');
globals.setKeyValue('test', undefined);
equal(globals.getKeyValue('test'), undefined);
assert.equal(globals.getKeyValue('test'), undefined);
});

QUnit.test('setKeyValue of existing property to a function', function() {
QUnit.test('setKeyValue of existing property to a function', function(assert) {
globals = new Globals();
globals.define('test', 'default');
globals.setKeyValue('test', function(){
return 'foo';
});
equal(globals.getKeyValue('test'), 'foo');
assert.equal(globals.getKeyValue('test'), 'foo');
});

QUnit.test('setKeyValue on an existing property should reset cache', function(){
QUnit.test('setKeyValue on an existing property should reset cache', function(assert) {
var globals = new Globals();
var bar = function() {
return 'bar';
Expand All @@ -118,18 +118,18 @@ QUnit.test('setKeyValue on an existing property should reset cache', function(){
globals.setKeyValue('foo', function(){
return 'baz';
});
equal(globals.getKeyValue('foo'), 'baz');
assert.equal(globals.getKeyValue('foo'), 'baz');
});

QUnit.test('deleteKeyValue to reset property to default', function() {
QUnit.test('deleteKeyValue to reset property to default', function(assert) {
var globals = new Globals();
globals.define('test', 'default');
globals.setKeyValue('test', 'updated');
globals.deleteKeyValue('test');
equal(globals.getKeyValue('test'), 'default');
assert.equal(globals.getKeyValue('test'), 'default');
});

QUnit.test('deleteKeyValue should clear cache', function() {
QUnit.test('deleteKeyValue should clear cache', function(assert) {
var globals = new Globals();
var bar = spy('bar');
globals.define('foo', bar);
Expand All @@ -139,10 +139,10 @@ QUnit.test('deleteKeyValue should clear cache', function() {
});
globals.deleteKeyValue('foo');
globals.getKeyValue('foo');
equal(bar.callCount, 2);
assert.equal(bar.callCount, 2);
});

QUnit.test('listen for key change', function() {
QUnit.test('listen for key change', function(assert) {
var globals = new Globals();
var handler = spy();
globals.define('test', 'default');
Expand All @@ -151,47 +151,47 @@ QUnit.test('listen for key change', function() {
globals.setKeyValue('test', 'updated');
globals.setKeyValue('foo', 'baz');
globals.deleteKeyValue('test');
equal(handler.callCount, 2);
deepEqual(mapEvents(handler), [
assert.equal(handler.callCount, 2);
assert.deepEqual(mapEvents(handler), [
'updated',
'default'
]);
globals.offKeyValue('test');
});

QUnit.test('remove event listener for key', function() {
QUnit.test('remove event listener for key', function(assert) {
var globals = new Globals();
var handler = spy();
globals.define('test', 'foo');
globals.onKeyValue('test', handler);
globals.offKeyValue('test', handler);
globals.setKeyValue('test', 'updated');
equal(handler.callCount, 0);
assert.equal(handler.callCount, 0);
});

QUnit.test('makeExport of key', function() {
QUnit.test('makeExport of key', function(assert) {
var globals = new Globals();
globals.define('foo', 'bar');
var e = globals.makeExport('foo');
equal(e(), 'bar');
assert.equal(e(), 'bar');
e('baz');
equal(e(), 'baz');
assert.equal(e(), 'baz');
e(undefined);
equal(e(), 'bar');
assert.equal(e(), 'bar');
});

QUnit.test('reset export value with null (can-stache#288)', function() {
QUnit.test('reset export value with null (can-stache#288)', function(assert) {
var globals = new Globals();
globals.define('foo', 'bar');
var e = globals.makeExport('foo');
equal(e(), 'bar');
assert.equal(e(), 'bar');
e('baz');
equal(e(), 'baz');
assert.equal(e(), 'baz');
e(null);
equal(e(), 'bar');
assert.equal(e(), 'bar');
});

QUnit.test('reset cleares cache on all keys', function(){
QUnit.test('reset cleares cache on all keys', function(assert) {
var globals = new Globals();
var bar = spy('bar');
var qux = spy('qux');
Expand All @@ -206,22 +206,22 @@ QUnit.test('reset cleares cache on all keys', function(){
globals.getKeyValue('foo');
globals.getKeyValue('baz');
}, 5);
equal(bar.callCount, 2);
equal(qux.callCount, 2);
assert.equal(bar.callCount, 2);
assert.equal(qux.callCount, 2);
});

QUnit.test('reset should reset all keys to default value (#31)', function(){
QUnit.test('reset should reset all keys to default value (#31)', function(assert) {
var globals = new Globals();
globals.define('foo', 'bar');
globals.define('baz', 'qux');
globals.setKeyValue('foo', 'red');
globals.setKeyValue('baz', 'green');
globals.reset();
equal(globals.getKeyValue('foo'), 'bar');
equal(globals.getKeyValue('baz'), 'qux');
assert.equal(globals.getKeyValue('foo'), 'bar');
assert.equal(globals.getKeyValue('baz'), 'qux');
});

QUnit.test('reset triggers events', function(){
QUnit.test('reset triggers events', function(assert) {
var globals = new Globals();
var fooHandler = spy();
var barHandler = spy();
Expand All @@ -232,46 +232,46 @@ QUnit.test('reset triggers events', function(){
globals.onKeyValue('foo', fooHandler);
globals.onKeyValue('bar', barHandler);
globals.reset();
equal(fooHandler.callCount, 1);
equal(barHandler.callCount, 1);
assert.equal(fooHandler.callCount, 1);
assert.equal(barHandler.callCount, 1);
globals.offKeyValue('foo');
globals.offKeyValue('bar');
});

QUnit.test('export helper value can be set to a function', function(){
QUnit.test('export helper value can be set to a function', function(assert) {
var globals = new Globals();
var foo = spy();
globals.setKeyValue('foo', function(){
return function(){};
});
var fooExport = globals.makeExport('foo');
fooExport(foo);
QUnit.equal(typeof fooExport(), 'function');
QUnit.equal(foo.callCount, 0);
assert.equal(typeof fooExport(), 'function');
assert.equal(foo.callCount, 0);
fooExport()();
QUnit.equal(foo.callCount, 1);
assert.equal(foo.callCount, 1);
});


QUnit.test('onKeyValue should dispatch the resolved value (#29)', function(){
QUnit.test('onKeyValue should dispatch the resolved value (#29)', function(assert) {
var globals = new Globals();
var foo = 'foo';
globals.define('foo', '');
globals.onKeyValue('foo', function(value){
QUnit.equal(value, foo);
assert.equal(value, foo);
});
globals.setKeyValue('foo', function(){
return foo;
});
globals.offKeyValue('foo');
});

QUnit.test('onKeyValue should not trigger multiple calls of the value function (#33)', function(){
QUnit.test('onKeyValue should not trigger multiple calls of the value function (#33)', function(assert) {
var globals = new Globals();
var baz = spy('baz');
globals.define('foo', 'bar');
globals.onKeyValue('foo', function(){});
globals.setKeyValue('foo', baz);
globals.getKeyValue('foo');
equal(baz.callCount, 1);
assert.equal(baz.callCount, 1);
});
14 changes: 7 additions & 7 deletions global/global-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ function isBrowserWindow(){

QUnit.module('can-globals/global/global');

test('basics', function(){
QUnit.test('basics', function(assert) {
if(isBrowserWindow()) {
ok(getGlobal() === window);
assert.ok(getGlobal() === window);
} else {
ok(getGlobal() === global);
assert.ok(getGlobal() === global);
}
});

if(!isBrowserWindow()) {
QUnit.module('in Node with fake window', {
setup: function(){
beforeEach: function(assert) {
this.oldWindow = global.window;
global.window = {};
},
teardown: function(){
afterEach: function(assert) {
global.window = this.oldWindow;
}
});

test('Gets the Node global', function(){
ok(getGlobal() === global);
QUnit.test('Gets the Node global', function(assert) {
assert.ok(getGlobal() === global);
});
}
4 changes: 2 additions & 2 deletions is-browser-window/is-browser-window-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var isBrowserWindow = require('./is-browser-window');

QUnit.module("can-globals/is-browser-window/is-browser-window");

QUnit.test("basics", function(){
equal(typeof isBrowserWindow(), "boolean");
QUnit.test("basics", function(assert) {
assert.equal(typeof isBrowserWindow(), "boolean");
});
4 changes: 2 additions & 2 deletions is-web-worker/is-web-worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var isWebWorker = require('./is-web-worker');

QUnit.module("can-globals/is-web-worker/is-web-worker");

QUnit.test("basics", function(){
equal(typeof isWebWorker(), "boolean");
QUnit.test("basics", function(assert) {
assert.equal(typeof isWebWorker(), "boolean");
});
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
"devDependencies": {
"detect-cyclic-packages": "^1.1.0",
"jshint": "^2.9.5",
"qunitjs": "^2.4.0",
"steal": "^2.2.1",
"steal-qunit": "^1.0.1",
"steal-qunit": "^2.0.0",
"steal-tools": "^2.2.1",
"testee": "^0.9.0"
}
Expand Down
8 changes: 4 additions & 4 deletions test-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ var isQunit = testType === 'qunit';
if (isMochaQUnitUI) {
// mocha-qunit-ui does not support async
QUnit.assert.async = function () {
QUnit.stop();
var done = assert.async();
return function done (error) {
if (error) {
return QUnit.ok(false, '' + error);
return assert.ok(false, '' + error);
}
QUnit.start();
done();
};
};

QUnit.test = test;
module.exports = QUnit;
} else if (isQunit) {
module.exports = require('qunitjs');
module.exports = require('qunit');
} else {
module.exports = require('steal-qunit');
}

0 comments on commit 702b6b5

Please sign in to comment.