forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLEANUP] Converting ember-runtime tests to new format
Apart of emberjs#15988
- Loading branch information
Showing
58 changed files
with
5,014 additions
and
4,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
|
||
} |
Oops, something went wrong.