Skip to content

Commit

Permalink
[CLEANUP] Converting ember-runtime tests to new format
Browse files Browse the repository at this point in the history
Apart of emberjs#15988
  • Loading branch information
thoov committed Mar 29, 2018
1 parent 462c33f commit 6cbc829
Show file tree
Hide file tree
Showing 58 changed files with 5,014 additions and 4,757 deletions.
86 changes: 42 additions & 44 deletions packages/ember-metal/tests/tracked/computed_test.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,66 @@
import { createWithDescriptors } from './support';
import { get, set, tracked } from '../..';

import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';

if (EMBER_METAL_TRACKED_PROPERTIES) {

QUnit.module('tracked getters');

QUnit.test('works without get', assert => {
let count = 0;

class Count {
get foo() {
count++;
return `computed foo`;
moduleFor('tracked getters', class extends AbstractTestCase {
['@test works without get'](assert) {
let count = 0;

class Count {
get foo() {
count++;
return `computed foo`;
}
}
}

tracked(Count.prototype, 'foo', Object.getOwnPropertyDescriptor(Count.prototype, 'foo'));
tracked(Count.prototype, 'foo', Object.getOwnPropertyDescriptor(Count.prototype, 'foo'));

let obj = new Count();

assert.equal(obj.foo, 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
});
let obj = new Count();

assert.equal(obj.foo, 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
}

QUnit.test('defining computed property should invoke property on get', function(assert) {
let count = 0;
['@test defining computed property should invoke property on get'](assert) {
let count = 0;

class Count {
get foo() {
count++;
return `computed foo`;
class Count {
get foo() {
count++;
return `computed foo`;
}
}
}

tracked(Count.prototype, 'foo', Object.getOwnPropertyDescriptor(Count.prototype, 'foo'));
tracked(Count.prototype, 'foo', Object.getOwnPropertyDescriptor(Count.prototype, 'foo'));

let obj = new Count();
let obj = new Count();

assert.equal(get(obj, 'foo'), 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
});
assert.equal(get(obj, 'foo'), 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
}


QUnit.test('defining computed property should invoke property on set', function(assert) {
let count = 0;
['@test defining computed property should invoke property on set'](assert) {
let count = 0;

let obj = createWithDescriptors({
get foo() {
return this.__foo;
},
let obj = createWithDescriptors({
get foo() {
return this.__foo;
},

set foo(value) {
count++;
this.__foo = `computed ${value}`;
}
});
set foo(value) {
count++;
this.__foo = `computed ${value}`;
}
});


assert.equal(set(obj, 'foo', 'bar'), 'bar', 'should return set value');
assert.equal(count, 1, 'should have invoked computed property');
assert.equal(get(obj, 'foo'), 'computed bar', 'should return new value');
assert.equal(set(obj, 'foo', 'bar'), 'bar', 'should return set value');
assert.equal(count, 1, 'should have invoked computed property');
assert.equal(get(obj, 'foo'), 'computed bar', 'should return new value');
}
});

}
Loading

0 comments on commit 6cbc829

Please sign in to comment.