Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landscaper: QUnit2 upgrade #690

Merged
merged 2 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions helpers/-and-or-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Observation = require("can-observation");

QUnit.module("can-stache and/or helper");

QUnit.test("and standalone", function(){
QUnit.test("and standalone", function(assert) {

var renders = [];
var view = stache("<div>{{#and(a,b)}}{{truthy(this)}}{{else}}{{falsey(this)}}{{/and}}</div>");
Expand All @@ -17,46 +17,46 @@ QUnit.test("and standalone", function(){
});

map.set("truthy", function(that){
QUnit.equal(that, map, "truthy this is right");
assert.equal(that, map, "truthy this is right");
renders.push("truthy");
return "truthy";
});
map.set("falsey", function(that){
QUnit.equal(that, map, "falsey this is right");
assert.equal(that, map, "falsey this is right");
renders.push("falsey");
return "falsey";
});
var frag = view(map);
QUnit.equal( frag.firstChild.innerHTML, "truthy", "1,1" );
assert.equal( frag.firstChild.innerHTML, "truthy", "1,1" );

// 2,2 ... stays truthy
canReflect.assign(map, {
a: 2,
b: 2
});
QUnit.equal( frag.firstChild.innerHTML, "truthy", "2,2" );
QUnit.deepEqual(renders,["truthy"], "2,2 render");
assert.equal( frag.firstChild.innerHTML, "truthy", "2,2" );
assert.deepEqual(renders,["truthy"], "2,2 render");
renders = [];

// 0,2
canReflect.assign(map, {
a: 0,
b: 2
});
QUnit.equal( frag.firstChild.innerHTML, "falsey", "0,2" );
QUnit.deepEqual(renders,["falsey"], "0,2 render");
assert.equal( frag.firstChild.innerHTML, "falsey", "0,2" );
assert.deepEqual(renders,["falsey"], "0,2 render");
renders = [];

// false, ""
canReflect.assign(map, {
a: false,
b: ""
});
QUnit.equal( frag.firstChild.innerHTML, "falsey", "false,''" );
QUnit.deepEqual(renders,[]);
assert.equal( frag.firstChild.innerHTML, "falsey", "false,''" );
assert.deepEqual(renders,[]);
});

QUnit.test("and as call expression", function(){
QUnit.test("and as call expression", function(assert) {

var renders = [];
var view = stache("<div>{{#eq( and(a,b), c) }}{{truthy(this)}}{{else}}{{falsey(this)}}{{/eq}}</div>");
Expand All @@ -68,46 +68,46 @@ QUnit.test("and as call expression", function(){
});

map.set("truthy", function(that){
QUnit.equal(that, map, "truthy this is right");
assert.equal(that, map, "truthy this is right");
renders.push("truthy");
return "truthy";
});
map.set("falsey", function(that){
QUnit.equal(that, map, "falsey this is right");
assert.equal(that, map, "falsey this is right");
renders.push("falsey");
return "falsey";
});
var frag = view(map);
QUnit.equal( frag.firstChild.innerHTML, "truthy", "(1 && 1 ) === 1" );
assert.equal( frag.firstChild.innerHTML, "truthy", "(1 && 1 ) === 1" );

// 2,2 ... stays truthy
canReflect.assign(map, {
a: 2,
});
QUnit.equal( frag.firstChild.innerHTML, "truthy", "(2 && 1 ) === 1" );
QUnit.deepEqual(renders,["truthy"]);
assert.equal( frag.firstChild.innerHTML, "truthy", "(2 && 1 ) === 1" );
assert.deepEqual(renders,["truthy"]);
renders = [];

// 2,0
canReflect.assign(map, {
a: 2,
b: 0
});
QUnit.equal( frag.firstChild.innerHTML, "falsey", "(2 && 0 ) === 1" );
QUnit.deepEqual(renders,["falsey"]);
assert.equal( frag.firstChild.innerHTML, "falsey", "(2 && 0 ) === 1" );
assert.deepEqual(renders,["falsey"]);
renders = [];

// false, ""
canReflect.assign(map, {
a: false,
b: ""
});
QUnit.equal( frag.firstChild.innerHTML, "falsey", "(false && '' ) === 1" );
QUnit.deepEqual(renders,[]);
assert.equal( frag.firstChild.innerHTML, "falsey", "(false && '' ) === 1" );
assert.deepEqual(renders,[]);
});


QUnit.test("or standalone", function(){
QUnit.test("or standalone", function(assert) {

var renders = [];
var view = stache("<div>{{#or(a,b)}}{{truthy(this)}}{{else}}{{falsey(this)}}{{/or}}</div>");
Expand All @@ -118,65 +118,65 @@ QUnit.test("or standalone", function(){
});

map.set("truthy", function(that){
QUnit.equal(that, map, "truthy this is right");
assert.equal(that, map, "truthy this is right");
renders.push("truthy");
return "truthy";
});
map.set("falsey", function(that){
QUnit.equal(that, map, "falsey this is right");
assert.equal(that, map, "falsey this is right");
renders.push("falsey");
return "falsey";
});
var frag = view(map);
QUnit.equal( frag.firstChild.innerHTML, "truthy", "1,1" );
assert.equal( frag.firstChild.innerHTML, "truthy", "1,1" );

// 2,2 ... stays truthy
canReflect.assign(map, {
a: 0,
b: 2
});
QUnit.equal( frag.firstChild.innerHTML, "truthy", "0,2" );
QUnit.deepEqual(renders,["truthy"], "0,2 render");
assert.equal( frag.firstChild.innerHTML, "truthy", "0,2" );
assert.deepEqual(renders,["truthy"], "0,2 render");
renders = [];

// 0,2
canReflect.assign(map, {
a: 0,
b: 0
});
QUnit.equal( frag.firstChild.innerHTML, "falsey", "0,0" );
QUnit.deepEqual(renders,["falsey"], "0,0 render");
assert.equal( frag.firstChild.innerHTML, "falsey", "0,0" );
assert.deepEqual(renders,["falsey"], "0,0 render");
renders = [];

// false, ""
canReflect.assign(map, {
a: false,
b: ""
});
QUnit.equal( frag.firstChild.innerHTML, "falsey", "false,''" );
QUnit.deepEqual(renders,[]);
assert.equal( frag.firstChild.innerHTML, "falsey", "false,''" );
assert.deepEqual(renders,[]);
});

QUnit.test("and is lazy", function(){
QUnit.test("and is lazy", function(assert) {
var view = stache("<div>{{#and(this.isFalse, this.shouldNotBeRead)}}TRUE{{else}}FALSE{{/and}}</div>");

var fragment = view({
isFalse: false,
shouldNotBeRead: new Observation(function avoidReadingThis(){
QUnit.ok(false, "should not be read");
assert.ok(false, "should not be read");
})
});

QUnit.equal(fragment.firstChild.innerHTML,"FALSE", "evaled to false");
assert.equal(fragment.firstChild.innerHTML,"FALSE", "evaled to false");

view = stache("<div>{{#and(this.isFalse, this.functionCall() )}}TRUE{{else}}FALSE{{/and}}</div>");

fragment = view({
isFalse: false,
functionCall: function(){
QUnit.ok(false, "should not be read");
assert.ok(false, "should not be read");
}
});

QUnit.equal(fragment.firstChild.innerHTML,"FALSE", "evaled to false");
assert.equal(fragment.firstChild.innerHTML,"FALSE", "evaled to false");
});
42 changes: 21 additions & 21 deletions helpers/-converter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var stache = require("can-stache");

QUnit.module("can-stache converters");

QUnit.test("addLiveConverter helpers push and pull correct values", function () {
QUnit.test("addLiveConverter helpers push and pull correct values", function(assert) {

helpers.addConverter('numberToHex', {
get: function(val) {
Expand All @@ -32,12 +32,12 @@ QUnit.test("addLiveConverter helpers push and pull correct values", function ()
//var renderer = stache('<input type="text" bound-attr="numberToHex(~observeVal)" />');


equal(twoWayCompute.get(), 'ff', 'Converter called');
assert.equal(twoWayCompute.get(), 'ff', 'Converter called');
twoWayCompute.set('7f');
equal(data.get("observeVal"), 127, 'push converter called');
assert.equal(data.get("observeVal"), 127, 'push converter called');
});

QUnit.test("addConverter helpers push and pull multiple values", function () {
QUnit.test("addConverter helpers push and pull multiple values", function(assert) {

helpers.addConverter('isInList', {
get: function(valCompute, list) {
Expand All @@ -63,23 +63,23 @@ QUnit.test("addConverter helpers push and pull multiple values", function () {
//var renderer = stache('<input type="text" bound-attr="numberToHex(~observeVal)" />');


equal(twoWayCompute.get(), false, 'Converter called');
assert.equal(twoWayCompute.get(), false, 'Converter called');
twoWayCompute.set(5);
deepEqual(data.attr("list").attr(), [1,2,3,5], 'push converter called');
assert.deepEqual(data.attr("list").attr(), [1,2,3,5], 'push converter called');
});

QUnit.test("Can register multiple converters at once with addConverter", function(){
QUnit.expect(2);
QUnit.test("Can register multiple converters at once with addConverter", function(assert) {
assert.expect(2);
var converters = {
"converter-one": {
get: function(){
QUnit.ok(true, "converter-one called");
assert.ok(true, "converter-one called");
},
set: function(){}
},
"converter-two": {
get: function(){
QUnit.ok(true, "converter-two called");
assert.ok(true, "converter-two called");
},
set: function(){}
}
Expand All @@ -100,7 +100,7 @@ QUnit.test("Can register multiple converters at once with addConverter", functio

QUnit.module("can-stache converters - not");

QUnit.test("saves the inverse of the selected value without ~ (#68)", function(){
QUnit.test("saves the inverse of the selected value without ~ (#68)", function(assert) {
var data = new SimpleMap({
val: true
});
Expand All @@ -110,13 +110,13 @@ QUnit.test("saves the inverse of the selected value without ~ (#68)", function()

var value = expr.value(scope);

QUnit.equal( value.get(), false , "read the value");
assert.equal( value.get(), false , "read the value");
value.set(true);

QUnit.equal( data.get("val"), false ,"able to change the value" );
assert.equal( data.get("val"), false ,"able to change the value" );
});

QUnit.test("not works also like if", function(){
QUnit.test("not works also like if", function(assert) {
var view = stache("<div>{{# not(this.value) }}{{truthy(this)}}{{else}}FALSY{{/not}}</div>");

var data = new SimpleMap({
Expand All @@ -125,18 +125,18 @@ QUnit.test("not works also like if", function(){

var frag = view(data,{
truthy: function(that){
QUnit.equal(that, data, "has the right scope");
assert.equal(that, data, "has the right scope");
return "TRUTHY";
}
});

QUnit.equal(frag.firstChild.innerHTML, "TRUTHY");
assert.equal(frag.firstChild.innerHTML, "TRUTHY");

data.set("value", true);
QUnit.equal(frag.firstChild.innerHTML, "FALSY");
assert.equal(frag.firstChild.innerHTML, "FALSY");
});

QUnit.test("not works inside if", function(){
QUnit.test("not works inside if", function(assert) {
var view = stache("<div>{{#if( not(this.value) ) }}{{truthy(this)}}{{else}}FALSY{{/if}}</div>");

var data = new SimpleMap({
Expand All @@ -145,13 +145,13 @@ QUnit.test("not works inside if", function(){

var frag = view(data,{
truthy: function(that){
QUnit.equal(that, data, "has the right scope");
assert.equal(that, data, "has the right scope");
return "TRUTHY";
}
});

QUnit.equal(frag.firstChild.innerHTML, "TRUTHY");
assert.equal(frag.firstChild.innerHTML, "TRUTHY");

data.set("value", true);
QUnit.equal(frag.firstChild.innerHTML, "FALSY");
assert.equal(frag.firstChild.innerHTML, "FALSY");
});
Loading