Skip to content

Commit

Permalink
Produce nicer error on malformed observer
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Dec 9, 2015
1 parent 68707ad commit 0e248f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/standard/effectBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@

_addComplexObserverEffect: function(observer) {
var sig = this._parseMethod(observer);

if (!sig) {
throw new Error("Malformed observer expression '" + observer + "'");
}

for (var i=0, arg; (i<sig.args.length) && (arg=sig.args[i]); i++) {
this._addPropertyEffect(arg.model, 'complexObserver', {
method: sig.method,
Expand Down
18 changes: 18 additions & 0 deletions test/unit/notify-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,24 @@

});

suite('malformed observers', function() {
test('has nice message on failure', function() {
var thrown = false;

try {
Polymer({
is: 'x-broken',
observers: ['foo(missingParenthesis']
});
} catch (e) {
assert.equal(e.message, "Malformed observer expression 'foo(missingParenthesis'");
thrown = true;
}

assert.equal(thrown, true, "No exception thrown when parsing malformed observer");
});
});

</script>

</body>
Expand Down

0 comments on commit 0e248f5

Please sign in to comment.