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

Refactor dev warning tests to use can-test-helpers #307

Merged
merged 2 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"can-event": "^3.6.0",
"can-list": "^3.2.0",
"can-map": "^3.3.0",
"can-test-helpers": "^1.0.0",
"can-vdom": "^3.1.0",
"jshint": "^2.9.4",
"steal": "^1.0.5",
Expand Down
182 changes: 93 additions & 89 deletions test/stache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var parser = require('can-view-parser');
var nodeLists = require('can-view-nodelist');
var canBatch = require('can-event/batch/batch');
var makeDocument = require('can-vdom/make-document/make-document');
var devHelpers = require('can-test-helpers/lib/dev');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have this in a module? I think we should just put everything on the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which package? In can-util alongside js/dev/ or in can-stache? If you mean can-stache, we really need the test helpers to be available elsewhere as we have warnings and errors that are tested elsewhere in the app.


var getChildNodes = require('can-util/dom/child-nodes/child-nodes');
var domData = require('can-util/dom/data/data');
Expand Down Expand Up @@ -195,23 +196,22 @@ function makeTest(name, doc, mutation) {
stache(template)(viewModel);
});

if (System.env.indexOf('production') < 0) {
devHelpers.devOnlyTest("helpers warn on overwrite (canjs/can-stache-converters#24)", function () {

test("helpers warn on overwrite (canjs/can-stache-converters#24)", function () {

var oldWarn = canDev.warn;
canDev.warn = function() {
stache.registerHelper('foobar', function() {});
// have to do this after the first registration b/c if the dom and vdom tests run, "foobar"
// will already have been registered.
var teardown = devHelpers.willWarn(/already been registered/, function(message, matched) {
if(matched) {
ok(true, "received warning");
};

stache.registerHelper('foobar', function() {});
stache.registerHelper('foobar', function() {});
}
});

canDev.warn = oldWarn;
stache.registerHelper('foobar', function() {});

});
QUnit.equal(teardown(), 1, "Exactly one warning called");

}
});

/*test("attribute sections", function(){
var stashed = stache("<h1 style='top: {{top}}px; left: {{left}}px; background: rgb(0,0,{{color}});'>Hi</h1>");
Expand Down Expand Up @@ -5506,60 +5506,62 @@ function makeTest(name, doc, mutation) {
}
});

if (System.env.indexOf('production') < 0) {
test("warn on missmatched tag (canjs/canjs#1476)", function() {
var makeWarnChecks = function(input, texts) {
var count = 0;
var _warn = canDev.warn;
canDev.warn = function(text) {
equal(text, texts[count++]);
};
devHelpers.devOnlyTest("warn on missmatched tag (canjs/canjs#1476)", function() {
var makeWarnChecks = function(input, texts) {
var count = 0;
var _warn = canDev.warn;
canDev.warn = function(text) {
equal(text, texts[count++]);
};

stache(input);
stache(input);

equal(count, texts.length);
equal(count, texts.length);

canDev.warn = _warn;
};
canDev.warn = _warn;
};

// Fails
makeWarnChecks("{{#if someCondition}}...{{/foo}}", [
"unexpected closing tag {{/foo}} expected {{/if}}"
]);
makeWarnChecks("{{^if someCondition}}...{{/foo}}", [
"unexpected closing tag {{/foo}} expected {{/if}}"
]);
makeWarnChecks("{{#call()}}...{{/foo}}", [
"unexpected closing tag {{/foo}} expected {{/call}}"
]);

// Successes
makeWarnChecks("{{#if}}...{{/}}", []);
makeWarnChecks("{{#if someCondition}}...{{/if}}", []);
makeWarnChecks("{{^if someCondition}}...{{/if}}", []);
makeWarnChecks("{{#call()}}...{{/call}}", []);
});
}
// Fails
makeWarnChecks("{{#if someCondition}}...{{/foo}}", [
"unexpected closing tag {{/foo}} expected {{/if}}"
]);
makeWarnChecks("{{^if someCondition}}...{{/foo}}", [
"unexpected closing tag {{/foo}} expected {{/if}}"
]);
makeWarnChecks("{{#call()}}...{{/foo}}", [
"unexpected closing tag {{/foo}} expected {{/call}}"
]);

if (System.env.indexOf('production') < 0) {
test("warn on unknown attributes (canjs/can-stache#139)", function(assert) {
var done = assert.async();
var warn = function(text) {
equal(text, "unknown attribute binding ($weirdattribute). Is can-stache-bindings imported?");
done();
};
clone({
'can-stache-bindings': {},
'can-util/js/dev/dev': {
warn: warn
// Successes
makeWarnChecks("{{#if}}...{{/}}", []);
makeWarnChecks("{{#if someCondition}}...{{/if}}", []);
makeWarnChecks("{{^if someCondition}}...{{/if}}", []);
makeWarnChecks("{{#call()}}...{{/call}}", []);
});

devHelpers.devOnlyTest("warn on unknown attributes (canjs/can-stache#139)", function(assert) {
var done = assert.async();
var teardown = devHelpers.willWarn(
"unknown attribute binding ($weirdattribute). Is can-stache-bindings imported?",
function(message, matched) {
if(matched) {
QUnit.ok(true, "warning logged");
teardown();
done();
}
})
.import('can-stache')
.then(function(stache) {
stache("<button ($weirdattribute)='showMessage()'>Click</button>");
});
}
);
clone({
'can-stache-bindings': {},
'can-util/js/dev/dev': {
warn: canDev.warn
}
})
.import('can-stache')
.then(function(stache) {
stache("<button ($weirdattribute)='showMessage()'>Click</button>");
});
}
});


test("@arg functions are not called (#172)", function() {
Expand Down Expand Up @@ -5799,41 +5801,43 @@ function makeTest(name, doc, mutation) {
ok( fraghtml.indexOf( "<li>goku<ul><li>gohan<ul><\/ul><\/li><\/ul><\/li>" ) !== -1 );
});

if (System.env.indexOf('production') < 0) {
test("warn when using on:, :to:on:, :to, :from or :bind without importing can-stache-bindings (#273)", function(assert) {
expect(5);
var expr = /unknown attribute binding/;
var warn = function(text) {
ok(expr.test(text));
};
clone({
'can-stache-bindings': {},
'can-util/js/dev/dev': {
warn: warn
}
})
.import('can-stache')
.then(function(stache) {
stache('<a on:click="theProp" value:to:on:click="theProp" value:to="theProp" value:from="theProp" value:bind="theProp">a link</a>');
});
devHelpers.devOnlyTest("warn when using on:, :to:on:, :to, :from or :bind without importing can-stache-bindings (#273)", function(assert) {
stop();
expect(6);
var teardown = devHelpers.willWarn(/unknown attribute binding/, function(message, matched) {
if(matched) {
QUnit.ok(matched, message);
}
});
clone({
'can-stache-bindings': {},
'can-util/js/dev/dev': {
warn: canDev.warn
}
})
.import('can-stache')
.then(function(stache) {
stache('<a on:click="theProp" value:to:on:click="theProp" value:to="theProp" value:from="theProp" value:bind="theProp">a link</a>');
QUnit.equal(teardown(), 5, "Every type of warning logged");
start();
});
});


test("Don't warn about tag mismatch for Call expressions with dots in the method lookup (#214)", function() {
var oldWarn = canDev.warn;
canDev.warn = function() {
devHelpers.devOnlyTest("Don't warn about tag mismatch for Call expressions with dots in the method lookup (#214)", function() {
var teardown = devHelpers.willWarn(/unexpected closing tag/, function(message, matched) {
if(matched) {
QUnit.ok(false, "Should not have warned about matching tags");
};
stache(
'{{#games.getAvailableCourts(selectedRound)}}' +
'<option value="{{.}}">{{.}}</option>' +
'{{/games.getAvailableCourts}}'
);

QUnit.ok(true, "Need an assertion");
canDev.warn = oldWarn;
}
});
}
stache(
'{{#games.getAvailableCourts(selectedRound)}}' +
'<option value="{{.}}">{{.}}</option>' +
'{{/games.getAvailableCourts}}'
);

QUnit.equal(teardown(), 0, "No warnings fired");
});

test('Bracket expression after `this` (canjs/can-stache/issues/173)', function () {
var template;
Expand Down