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

Add failing test cases for ES6 classes #61

Closed
Closed
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
44 changes: 44 additions & 0 deletions tests/unit/computed-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,47 @@ test('attr.@each.{foo,bar} passes attr', function(assert) {
get(obj, 'something');
set(obj, 'something', 'something');
});

test('works with es6 class', function(assert) {
assert.expect(2);

class Foo {
constructor() {
this.first = 'rob';
this.last = 'jackson';
}

/* jshint ignore:start */
@computed('first', 'last')
/* jshint ignore:end */
fullName(first, last) {
assert.equal(first, 'rob');
assert.equal(last, 'jackson');
}
}

let obj = new Foo();
get(obj, 'fullName');
});

test('works with es6 class getter', function(assert) {
assert.expect(2);

class Foo {
constructor() {
this.first = 'rob';
this.last = 'jackson';
}

/* jshint ignore:start */
@computed('first', 'last')
/* jshint ignore:end */
get fullName() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We explicitly throw on this:

ember-decorators does not support using getters and setters

I think mostly because we haven't thought it through just yet.

Thoughts @stefanpenner / @pzuraq?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can do this, we just have to figure out how to reach into existing descriptors in cases where both a getter and setter are used. I'll try to find some time later today to spike it out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ya, I think it makes sense for @computed (for example), but not all of them. e.g. @observer with a getter or setter is pretty WAT...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah definitely, this should probably only be for @computed (can't think of another one where it would make sense tbh)

assert.equal(this.first, 'rob');
assert.equal(this.last, 'jackson');
}
}

let obj = new Foo();
get(obj, 'fullName');
});