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

Use default noop function for unregistered tags. #59

Merged
merged 1 commit into from
Sep 29, 2017
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
4 changes: 3 additions & 1 deletion can-view-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var attr = function (attributeName, attrHandler) {
var attributes = {},
regExpAttributes = [],
automaticCustomElementCharacters = /[-\:]/;
var defaultCallback = function () {};

var tag = function (tagName, tagHandler) {
if(tagHandler) {
Expand Down Expand Up @@ -82,7 +83,7 @@ var tag = function (tagName, tagHandler) {

if(!cb && automaticCustomElementCharacters.test(tagName)) {
// empty callback for things that look like special tags
cb = function(){};
cb = defaultCallback;
}
return cb;
}
Expand All @@ -94,6 +95,7 @@ var callbacks = {
_tags: tags,
_attributes: attributes,
_regExpAttributes: regExpAttributes,
defaultCallback: defaultCallback,
tag: tag,
attr: attr,
// handles calling back a tag callback
Expand Down
8 changes: 8 additions & 0 deletions test/callbacks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,12 @@ if (System.env.indexOf('production') < 0) {
// callback attr provided
callbacks.attr(attrMatch, function(){});
});

QUnit.test("tag method should return default callback when valid tag but not registered", function () {
equal(callbacks.tag('not-exist'), callbacks.defaultCallback, "used default noop function")
});

QUnit.test("tag method should return undefined when invalid tag and not registered", function () {
notOk(callbacks.tag('notexist'), "used default noop function")
});
}