Skip to content

Commit

Permalink
Improve warning message for get-with-no-set condition
Browse files Browse the repository at this point in the history
  • Loading branch information
bmomberger-bitovi committed Aug 31, 2017
1 parent 5a04e5e commit 97f89bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion can-define.js
Expand Up @@ -262,8 +262,9 @@ define.property = function(objPrototype, prop, definition, dataInitializers, com
// If there's zero-arg `get` but not `set`, warn on all sets in dev mode
else if (definition.get.length < 1) {
setter = function() {
dev.warn("Set value for property " +
dev.warn("can-define: Set value for property " +
prop +
(objPrototype.constructor.shortName ? " on " + objPrototype.constructor.shortName : "") +
" ignored, as its definition has a zero-argument getter and no setter");
};
}
Expand Down
14 changes: 12 additions & 2 deletions define-test.js
Expand Up @@ -1372,7 +1372,7 @@ QUnit.test('define() should add a CID (#246)', function() {

if(System.env.indexOf("production") < 0) {
QUnit.test('Setting a value with only a get() generates a warning (#202)', function() {
QUnit.expect(2);
QUnit.expect(3);
var VM = function() {};
define(VM.prototype, {
derivedProp: {
Expand All @@ -1389,12 +1389,22 @@ if(System.env.indexOf("production") < 0) {
canDev.warn = function(mesg) {
QUnit.equal(
mesg,
"Set value for property derivedProp ignored, as its definition has a zero-argument getter and no setter",
"can-define: Set value for property derivedProp ignored, as its definition has a zero-argument getter and no setter",
"Warning is expected message");
};

vm.derivedProp = 'prop is set';
QUnit.equal(vm.derivedProp, "Hello World", "Getter value is preserved");

VM.shortName = "VM";
canDev.warn = function(mesg) {
QUnit.equal(
mesg,
"can-define: Set value for property derivedProp on VM ignored, as its definition has a zero-argument getter and no setter",
"Warning is expected message");
};

vm.derivedProp = 'prop is set';
canDev.warn = oldwarn;
});
}

0 comments on commit 97f89bd

Please sign in to comment.