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

[BUGFIX beta] CPs check presence of getter function #12156

Merged
merged 1 commit into from
Aug 23, 2015
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
11 changes: 11 additions & 0 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,20 @@ function ComputedProperty(config, opts) {
if (typeof config === 'function') {
this._getter = config;
} else {
Ember.assert('Ember.computed expects a function or an object as last argument.', typeof config === 'object' && !Array.isArray(config));
Ember.assert('Config object pased to a Ember.computed can only contain `get` or `set` keys.', (function() {
let keys = Object.keys(config);
for (let i = 0; i < keys.length; i++) {
if (keys[i] !== 'get' && keys[i] !== 'set') {
return false;
}
}
return true;
})());
this._getter = config.get;
this._setter = config.set;
}
Ember.assert('Computed properties must receive a getter or a setter, you passed none.', !!this._getter || !!this._setter);
this._dependentKeys = undefined;
this._suspended = undefined;
this._meta = undefined;
Expand Down
23 changes: 23 additions & 0 deletions packages/ember-metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ QUnit.test('computed property should be an instance of descriptor', function() {
ok(computed(function() {}) instanceof Descriptor);
});

QUnit.test('computed properties assert the presence of a getter or setter function', function() {
expectAssertion(function() {
computed('nogetternorsetter', {});
}, 'Computed properties must receive a getter or a setter, you passed none.');
});

QUnit.test('computed properties check for the presence of a function or configuration object', function() {
expectAssertion(function() {
computed('nolastargument');
}, 'Ember.computed expects a function or an object as last argument.');
});

QUnit.test('computed properties defined with an object only allow `get` and `set` keys', function() {
expectAssertion(function() {
computed({
get() {},
set() {},
other() {}
});
}, 'Config object pased to a Ember.computed can only contain `get` or `set` keys.');
});


QUnit.test('defining computed property should invoke property on get', function() {
var obj = {};
var count = 0;
Expand Down