Skip to content

Commit

Permalink
Merge pull request #352 from canjs/landscaper/qunit2
Browse files Browse the repository at this point in the history
Landscaper: QUnit2 upgrade
  • Loading branch information
cherifGsoul authored May 24, 2019
2 parents bd4595f + 674efef commit 87f9388
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 344 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"gh-pages": "^2.0.1",
"jshint": "^2.9.1",
"steal": "^1.0.0",
"steal-qunit": "^1.0.0",
"steal-qunit": "^2.0.0",
"steal-tools": "^1.0.1",
"testee": "^0.9.0"
}
Expand Down
54 changes: 27 additions & 27 deletions test/component-define-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var testHelpers = require("can-test-helpers");

QUnit.module("can-component with can-define");

QUnit.test('Works with can-define', function () {
QUnit.test('Works with can-define', function(assert) {

var VM = define.Constructor({
firstName: {
Expand Down Expand Up @@ -40,25 +40,25 @@ QUnit.test('Works with can-define', function () {

var vm = viewModel(frag.firstChild);

QUnit.ok(vm instanceof VM, 'Constructor was called');
QUnit.equal(vm.firstName, 'Chris', 'ViewModel was set from scope');
QUnit.equal(vm.lastName, 'Gomez', 'ViewModel was set from scope');
QUnit.equal(frag.firstChild.innerHTML, 'Name: Chris Gomez', 'Rendered fullName');
assert.ok(vm instanceof VM, 'Constructor was called');
assert.equal(vm.firstName, 'Chris', 'ViewModel was set from scope');
assert.equal(vm.lastName, 'Gomez', 'ViewModel was set from scope');
assert.equal(frag.firstChild.innerHTML, 'Name: Chris Gomez', 'Rendered fullName');

vm.firstName = 'Justin';
vm.lastName = 'Meyer';

QUnit.equal(frag.firstChild.innerHTML, 'Name: Justin Meyer', 'Rendered fullName after change');
assert.equal(frag.firstChild.innerHTML, 'Name: Justin Meyer', 'Rendered fullName after change');
});


QUnit.test('scope method works', function () {
QUnit.test('scope method works', function(assert) {


Component.extend({
tag: "my-element",
viewModel: function(properties, scope, element){
QUnit.deepEqual(properties, {first: "Justin", last: "Meyer"});
assert.deepEqual(properties, {first: "Justin", last: "Meyer"});
return new DefineMap(properties);
}
});
Expand All @@ -70,14 +70,14 @@ QUnit.test('scope method works', function () {

});

QUnit.test('33 - works when instantiated with an object for ViewModel', function () {
QUnit.test('33 - works when instantiated with an object for ViewModel', function(assert) {

Component.extend({
tag: "test-element",
view: stache("{{someMethod()}}"),
ViewModel: {
someMethod: function() {
ok(true, "Function got called");
assert.ok(true, "Function got called");
return true;
}
}
Expand All @@ -88,7 +88,7 @@ QUnit.test('33 - works when instantiated with an object for ViewModel', function

});

QUnit.test("helpers do not leak when leakscope is false (#77)", function () {
QUnit.test("helpers do not leak when leakscope is false (#77)", function(assert) {
var called = 0;
Component.extend({
tag: "inner-el",
Expand All @@ -109,10 +109,10 @@ QUnit.test("helpers do not leak when leakscope is false (#77)", function () {
var renderer = stache("<outer-el>");

renderer();
QUnit.equal(called, 0, "Outer helper not called");
assert.equal(called, 0, "Outer helper not called");
});

QUnit.test("helpers do leak when leakscope is true (#77)", function () {
QUnit.test("helpers do leak when leakscope is true (#77)", function(assert) {
var called = 0;
Component.extend({
tag: "inner-el",
Expand All @@ -133,15 +133,15 @@ QUnit.test("helpers do leak when leakscope is true (#77)", function () {
var renderer = stache("<outer-el/>");

renderer();
QUnit.equal(called, 1, "Outer helper called once");
assert.equal(called, 1, "Outer helper called once");
});

if(System.env.indexOf("production") < 0) {
QUnit.test('warn if viewModel is assigned a DefineMap (#14)', function() {
QUnit.expect(1);
QUnit.test('warn if viewModel is assigned a DefineMap (#14)', function(assert) {
assert.expect(1);
var oldwarn = canDev.warn;
canDev.warn = function(mesg) {
QUnit.equal(mesg, "can-component: Assigning a DefineMap or constructor type to the viewModel property may not be what you intended. Did you mean ViewModel instead? More info: https://canjs.com/doc/can-component.prototype.ViewModel.html", "Warning is expected message");
assert.equal(mesg, "can-component: Assigning a DefineMap or constructor type to the viewModel property may not be what you intended. Did you mean ViewModel instead? More info: https://canjs.com/doc/can-component.prototype.ViewModel.html", "Warning is expected message");
};

// should issue a warning
Expand All @@ -161,7 +161,7 @@ if(System.env.indexOf("production") < 0) {
});
}

QUnit.test("ViewModel defaults to DefineMap if set to an Object", function() {
QUnit.test("ViewModel defaults to DefineMap if set to an Object", function(assert) {
Component.extend({
tag: 'can-define-component',
ViewModel: {
Expand All @@ -187,18 +187,18 @@ QUnit.test("ViewModel defaults to DefineMap if set to an Object", function() {

var vm = viewModel(frag.firstChild);

QUnit.ok(vm instanceof DefineMap, 'vm is a DefineMap');
QUnit.equal(vm.firstName, 'Chris', 'ViewModel was set from scope');
QUnit.equal(vm.lastName, 'Gomez', 'ViewModel was set from scope');
QUnit.equal(frag.firstChild.innerHTML, 'Name: Chris Gomez', 'Rendered fullName');
assert.ok(vm instanceof DefineMap, 'vm is a DefineMap');
assert.equal(vm.firstName, 'Chris', 'ViewModel was set from scope');
assert.equal(vm.lastName, 'Gomez', 'ViewModel was set from scope');
assert.equal(frag.firstChild.innerHTML, 'Name: Chris Gomez', 'Rendered fullName');

vm.firstName = 'Justin';
vm.lastName = 'Meyer';

QUnit.equal(frag.firstChild.innerHTML, 'Name: Justin Meyer', 'Rendered fullName after change');
assert.equal(frag.firstChild.innerHTML, 'Name: Justin Meyer', 'Rendered fullName after change');
});

QUnit.test("ViewModel properties default to DefineList if set to an Array (#225)", function() {
QUnit.test("ViewModel properties default to DefineList if set to an Array (#225)", function(assert) {
Component.extend({
tag: "viewmodel-lists",
view: "Hello, World",
Expand All @@ -216,10 +216,10 @@ QUnit.test("ViewModel properties default to DefineList if set to an Array (#225)
var fragOne = renderer();
var vm = viewModel(fragOne.firstChild);

QUnit.ok(vm.items instanceof define.DefineList, 'vm is a DefineList');
assert.ok(vm.items instanceof define.DefineList, 'vm is a DefineList');
});

testHelpers.dev.devOnlyTest("filename should be passed to stache() for inline views", function() {
testHelpers.dev.devOnlyTest("filename should be passed to stache() for inline views", function (assert) {
Component.extend({
tag: "my-filename-component",
ViewModel: {},
Expand All @@ -229,5 +229,5 @@ testHelpers.dev.devOnlyTest("filename should be passed to stache() for inline vi
var renderer = stache("<my-filename-component></my-filename-component>");
var frag = renderer();

QUnit.equal(frag.firstChild.innerHTML, "MyFilenameComponentView", "filename was provided to stache()");
assert.equal(frag.firstChild.innerHTML, "MyFilenameComponentView", "filename was provided to stache()");
});
54 changes: 28 additions & 26 deletions test/component-events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var removedEvent = domMutateDomEvents.removed;

helpers.makeTests("can-component events", function(){

test("value observables formerly (#550)", function () {
QUnit.test("value observables formerly (#550)", function(assert) {

var nameChanges = 0;

Expand Down Expand Up @@ -45,17 +45,17 @@ helpers.makeTests("can-component events", function(){
n2.set("updated");


equal(nameChanges, 2);
assert.equal(nameChanges, 2);
});

test("Component events bind to window", function(){
QUnit.test("Component events bind to window", function(assert) {
window.tempMap = new SimpleMap();

Component.extend({
tag: "window-events",
events: {
"{tempMap} prop": function(){
ok(true, "called templated event");
assert.ok(true, "called templated event");
}
}
});
Expand All @@ -75,8 +75,8 @@ helpers.makeTests("can-component events", function(){

});

QUnit.test("stache conditionally nested components calls inserted once (#967)", function(){
expect(1);
QUnit.test("stache conditionally nested components calls inserted once (#967)", function(assert) {
assert.expect(1);
var undo = domEvents.addEvent(insertedEvent);

Component.extend({
Expand All @@ -92,24 +92,25 @@ helpers.makeTests("can-component events", function(){
tag: "can-child",
events: {
inserted: function(){
ok(true, "called inserted once");
assert.ok(true, "called inserted once");
}
}
});

var renderer = stache("<can-parent-stache></can-parent-stache>");

domMutateNode.appendChild.call(this.fixture, renderer());
stop();
var done = assert.async();
setTimeout(function () {
undo();
start();
done();
}, 100);
});


QUnit.test('viewModel objects with Constructor functions as properties do not get converted (#1261)', 1, function(){
stop();
QUnit.test('viewModel objects with Constructor functions as properties do not get converted (#1261)', function(assert) {
assert.expect(1);
var done = assert.async();
var HANDLER;
var Test = SimpleMap.extend({
addEventListener: function(ev, handler){
Expand All @@ -133,8 +134,8 @@ helpers.makeTests("can-component events", function(){
}),
events: {
'{MyConstruct} something': function() {
ok(true, 'Event got triggered');
start();
assert.ok(true, 'Event got triggered');
done();
}
}
});
Expand All @@ -146,7 +147,7 @@ helpers.makeTests("can-component events", function(){
HANDLER.call(Test,{type:"something"});
});

QUnit.test('removing bound viewModel properties on destroy #1415', function(){
QUnit.test('removing bound viewModel properties on destroy #1415', function(assert) {
var state = new SimpleMap({
product: new SimpleMap({
id: 1,
Expand All @@ -169,25 +170,26 @@ helpers.makeTests("can-component events", function(){
domMutateNode.appendChild.call(this.fixture,frag);

domMutateNode.removeChild.call(this.fixture, this.fixture.firstChild);
stop();
var done = assert.async();
helpers.afterMutation(function(){
ok(state.attr('product') == null, 'product was removed');
start();
assert.ok(state.attr('product') == null, 'product was removed');
done();
});
});

test('changing viewModel property rebinds {viewModel.<...>} events (#1529)', 2, function(){
QUnit.test('changing viewModel property rebinds {viewModel.<...>} events (#1529)', function(assert) {
assert.expect(2);
Component.extend({
tag: 'rebind-viewmodel',
events: {
init: function(){
this.viewModel.set("anItem" , new SimpleMap({}) );
},
'{scope.anItem} name': function() {
ok(true, 'Change event on scope');
assert.ok(true, 'Change event on scope');
},
'{viewModel.anItem} name': function() {
ok(true, 'Change event on viewModel');
assert.ok(true, 'Change event on viewModel');
}
}
});
Expand All @@ -199,7 +201,7 @@ helpers.makeTests("can-component events", function(){
});


QUnit.test('DOM trees not releasing when referencing CanMap inside CanMap in view (#1593)', function() {
QUnit.test('DOM trees not releasing when referencing CanMap inside CanMap in view (#1593)', function(assert) {
var undo = domEvents.addEvent(removedEvent);

var baseTemplate = stache('{{#if show}}<my-outside></my-outside>{{/if}}'),
Expand Down Expand Up @@ -230,24 +232,24 @@ helpers.makeTests("can-component events", function(){
show: show,
state: state
}));

var done = assert.async();
helpers.runTasks([function(){
show.set(false);
},function(){
state.set('inner', null);
}, function(){
equal(removeCount, 1, 'internal removed once');
assert.equal(removeCount, 1, 'internal removed once');
show.set(true);
}, function(){
state.set('inner', 2);
}, function(){
state.set('inner', null);
}, function(){
equal(removeCount, 2, 'internal removed twice');
assert.equal(removeCount, 2, 'internal removed twice');
undo();
}]);
}], done);

stop();


});

Expand Down
8 changes: 4 additions & 4 deletions test/component-helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var Component = require("can-component");

helpers.makeTests("can-component helpers", function(){

QUnit.test("helpers reference the correct instance (#515)", function () {
expect(2);
QUnit.test("helpers reference the correct instance (#515)", function(assert) {
assert.expect(2);
Component({
tag: 'my-text',
view: stache('<p>{{valueHelper()}}</p>'),
Expand All @@ -22,7 +22,7 @@ helpers.makeTests("can-component helpers", function(){

var frag = renderer({});

equal(frag.firstChild.firstChild.firstChild.nodeValue, 'value1');
equal(frag.lastChild.firstChild.firstChild.nodeValue, 'value2');
assert.equal(frag.firstChild.firstChild.firstChild.nodeValue, 'value1');
assert.equal(frag.lastChild.firstChild.firstChild.nodeValue, 'value2');
});
});
Loading

0 comments on commit 87f9388

Please sign in to comment.