Skip to content

Commit ce4065d

Browse files
committed
[CLEANUP] Convert ember-metal tests over to new style
Apart of #15988
1 parent 0931537 commit ce4065d

18 files changed

+2157
-2112
lines changed

packages/ember-metal/tests/alias_test.js

+72-69
Original file line numberDiff line numberDiff line change
@@ -9,102 +9,105 @@ import {
99
removeObserver,
1010
tagFor
1111
} from '..';
12+
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
1213

1314
let obj, count;
1415

15-
QUnit.module('ember-metal/alias', {
16+
function incrementCount() {
17+
count++;
18+
}
19+
20+
moduleFor('ember-metal/alias', class extends AbstractTestCase {
1621
beforeEach() {
1722
obj = { foo: { faz: 'FOO' } };
1823
count = 0;
19-
},
24+
}
25+
2026
afterEach() {
2127
obj = null;
2228
}
23-
});
2429

25-
function incrementCount() {
26-
count++;
27-
}
30+
['@test should proxy get to alt key'](assert) {
31+
defineProperty(obj, 'bar', alias('foo.faz'));
32+
assert.equal(get(obj, 'bar'), 'FOO');
33+
}
2834

29-
QUnit.test('should proxy get to alt key', function(assert) {
30-
defineProperty(obj, 'bar', alias('foo.faz'));
31-
assert.equal(get(obj, 'bar'), 'FOO');
32-
});
35+
['@test should proxy set to alt key'](assert) {
36+
defineProperty(obj, 'bar', alias('foo.faz'));
37+
set(obj, 'bar', 'BAR');
38+
assert.equal(get(obj, 'foo.faz'), 'BAR');
39+
}
3340

34-
QUnit.test('should proxy set to alt key', function(assert) {
35-
defineProperty(obj, 'bar', alias('foo.faz'));
36-
set(obj, 'bar', 'BAR');
37-
assert.equal(get(obj, 'foo.faz'), 'BAR');
38-
});
41+
['@test old dependent keys should not trigger property changes'](assert) {
42+
let obj1 = Object.create(null);
43+
defineProperty(obj1, 'foo', null, null);
44+
defineProperty(obj1, 'bar', alias('foo'));
45+
defineProperty(obj1, 'baz', alias('foo'));
46+
defineProperty(obj1, 'baz', alias('bar')); // redefine baz
47+
addObserver(obj1, 'baz', incrementCount);
3948

40-
QUnit.test('old dependent keys should not trigger property changes', function(assert) {
41-
let obj1 = Object.create(null);
42-
defineProperty(obj1, 'foo', null, null);
43-
defineProperty(obj1, 'bar', alias('foo'));
44-
defineProperty(obj1, 'baz', alias('foo'));
45-
defineProperty(obj1, 'baz', alias('bar')); // redefine baz
46-
addObserver(obj1, 'baz', incrementCount);
49+
set(obj1, 'foo', 'FOO');
50+
assert.equal(count, 1);
4751

48-
set(obj1, 'foo', 'FOO');
49-
assert.equal(count, 1);
52+
removeObserver(obj1, 'baz', incrementCount);
5053

51-
removeObserver(obj1, 'baz', incrementCount);
54+
set(obj1, 'foo', 'OOF');
55+
assert.equal(count, 1);
56+
}
5257

53-
set(obj1, 'foo', 'OOF');
54-
assert.equal(count, 1);
55-
});
58+
[`@test inheriting an observer of the alias from the prototype then
59+
redefining the alias on the instance to another property dependent on same key
60+
does not call the observer twice`](assert) {
61+
let obj1 = Object.create(null);
5662

57-
QUnit.test(`inheriting an observer of the alias from the prototype then
58-
redefining the alias on the instance to another property dependent on same key
59-
does not call the observer twice`, function(assert) {
60-
let obj1 = Object.create(null);
63+
meta(obj1).proto = obj1;
6164

62-
meta(obj1).proto = obj1;
65+
defineProperty(obj1, 'foo', null, null);
66+
defineProperty(obj1, 'bar', alias('foo'));
67+
defineProperty(obj1, 'baz', alias('foo'));
68+
addObserver(obj1, 'baz', incrementCount);
6369

64-
defineProperty(obj1, 'foo', null, null);
65-
defineProperty(obj1, 'bar', alias('foo'));
66-
defineProperty(obj1, 'baz', alias('foo'));
67-
addObserver(obj1, 'baz', incrementCount);
70+
let obj2 = Object.create(obj1);
71+
defineProperty(obj2, 'baz', alias('bar')); // override baz
6872

69-
let obj2 = Object.create(obj1);
70-
defineProperty(obj2, 'baz', alias('bar')); // override baz
73+
set(obj2, 'foo', 'FOO');
74+
assert.equal(count, 1);
7175

72-
set(obj2, 'foo', 'FOO');
73-
assert.equal(count, 1);
76+
removeObserver(obj2, 'baz', incrementCount);
7477

75-
removeObserver(obj2, 'baz', incrementCount);
78+
set(obj2, 'foo', 'OOF');
79+
assert.equal(count, 1);
80+
}
7681

77-
set(obj2, 'foo', 'OOF');
78-
assert.equal(count, 1);
79-
});
82+
['@test an observer of the alias works if added after defining the alias'](assert) {
83+
defineProperty(obj, 'bar', alias('foo.faz'));
84+
addObserver(obj, 'bar', incrementCount);
85+
assert.ok(isWatching(obj, 'foo.faz'));
86+
set(obj, 'foo.faz', 'BAR');
87+
assert.equal(count, 1);
88+
}
8089

81-
QUnit.test('an observer of the alias works if added after defining the alias', function(assert) {
82-
defineProperty(obj, 'bar', alias('foo.faz'));
83-
addObserver(obj, 'bar', incrementCount);
84-
assert.ok(isWatching(obj, 'foo.faz'));
85-
set(obj, 'foo.faz', 'BAR');
86-
assert.equal(count, 1);
87-
});
90+
['@test an observer of the alias works if added before defining the alias'](assert) {
91+
addObserver(obj, 'bar', incrementCount);
92+
defineProperty(obj, 'bar', alias('foo.faz'));
93+
assert.ok(isWatching(obj, 'foo.faz'));
94+
set(obj, 'foo.faz', 'BAR');
95+
assert.equal(count, 1);
96+
}
8897

89-
QUnit.test('an observer of the alias works if added before defining the alias', function(assert) {
90-
addObserver(obj, 'bar', incrementCount);
91-
defineProperty(obj, 'bar', alias('foo.faz'));
92-
assert.ok(isWatching(obj, 'foo.faz'));
93-
set(obj, 'foo.faz', 'BAR');
94-
assert.equal(count, 1);
95-
});
98+
['@test object with alias is dirtied if interior object of alias is set after consumption'](assert) {
99+
defineProperty(obj, 'bar', alias('foo.faz'));
100+
get(obj, 'bar');
96101

97-
QUnit.test('object with alias is dirtied if interior object of alias is set after consumption', function(assert) {
98-
defineProperty(obj, 'bar', alias('foo.faz'));
99-
get(obj, 'bar');
102+
let tag = tagFor(obj);
103+
let tagValue = tag.value();
104+
set(obj, 'foo.faz', 'BAR');
100105

101-
let tag = tagFor(obj);
102-
let tagValue = tag.value();
103-
set(obj, 'foo.faz', 'BAR');
106+
assert.ok(!tag.validate(tagValue), 'setting the aliased key should dirty the object');
107+
}
104108

105-
assert.ok(!tag.validate(tagValue), 'setting the aliased key should dirty the object');
109+
['@test setting alias on self should fail assertion']() {
110+
expectAssertion(() => defineProperty(obj, 'bar', alias('bar')), 'Setting alias \'bar\' on self');
111+
}
106112
});
107113

108-
QUnit.test('setting alias on self should fail assertion', function() {
109-
expectAssertion(() => defineProperty(obj, 'bar', alias('bar')), 'Setting alias \'bar\' on self');
110-
});

packages/ember-metal/tests/cache_test.js

+82-80
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,95 @@
11
import { Cache } from '..';
2+
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
23

3-
QUnit.module('Cache');
4+
moduleFor('Cache', class extends AbstractTestCase {
5+
['@test basic'](assert) {
6+
let cache = new Cache(100, key => key.toUpperCase());
47

5-
QUnit.test('basic', function(assert) {
6-
let cache = new Cache(100, key => key.toUpperCase());
8+
assert.equal(cache.get('foo'), 'FOO');
9+
assert.equal(cache.get('bar'), 'BAR');
10+
assert.equal(cache.get('foo'), 'FOO');
11+
}
712

8-
assert.equal(cache.get('foo'), 'FOO');
9-
assert.equal(cache.get('bar'), 'BAR');
10-
assert.equal(cache.get('foo'), 'FOO');
11-
});
12-
13-
QUnit.test('explicit sets', function(assert) {
14-
let cache = new Cache(100, key => key.toUpperCase());
13+
['@test explicit sets'](assert) {
14+
let cache = new Cache(100, key => key.toUpperCase());
1515

16-
assert.equal(cache.get('foo'), 'FOO');
16+
assert.equal(cache.get('foo'), 'FOO');
1717

18-
assert.equal(cache.set('foo', 'FOO!!!'), 'FOO!!!');
18+
assert.equal(cache.set('foo', 'FOO!!!'), 'FOO!!!');
1919

20-
assert.equal(cache.get('foo'), 'FOO!!!');
20+
assert.equal(cache.get('foo'), 'FOO!!!');
2121

22-
assert.strictEqual(cache.set('foo', undefined), undefined);
22+
assert.strictEqual(cache.set('foo', undefined), undefined);
2323

24-
assert.strictEqual(cache.get('foo'), undefined);
25-
});
26-
27-
QUnit.test('caches computation correctly', function(assert) {
28-
let count = 0;
29-
let cache = new Cache(100, key => {
30-
count++;
31-
return key.toUpperCase();
32-
});
33-
34-
assert.equal(count, 0);
35-
cache.get('foo');
36-
assert.equal(count, 1);
37-
cache.get('bar');
38-
assert.equal(count, 2);
39-
cache.get('bar');
40-
assert.equal(count, 2);
41-
cache.get('foo');
42-
assert.equal(count, 2);
43-
});
24+
assert.strictEqual(cache.get('foo'), undefined);
25+
}
4426

45-
QUnit.test('caches computation correctly with custom cache keys', function(assert) {
46-
let count = 0;
47-
let cache = new Cache(
48-
100,
49-
obj => {
27+
['@test caches computation correctly'](assert) {
28+
let count = 0;
29+
let cache = new Cache(100, key => {
5030
count++;
51-
return obj.value.toUpperCase();
52-
},
53-
obj => obj.key
54-
);
55-
56-
assert.equal(count, 0);
57-
cache.get({ key: 'foo', value: 'foo' });
58-
assert.equal(count, 1);
59-
cache.get({ key: 'bar', value: 'bar' });
60-
assert.equal(count, 2);
61-
cache.get({ key: 'bar', value: 'bar' });
62-
assert.equal(count, 2);
63-
cache.get({ key: 'foo', value: 'foo' });
64-
assert.equal(count, 2);
31+
return key.toUpperCase();
32+
});
33+
34+
assert.equal(count, 0);
35+
cache.get('foo');
36+
assert.equal(count, 1);
37+
cache.get('bar');
38+
assert.equal(count, 2);
39+
cache.get('bar');
40+
assert.equal(count, 2);
41+
cache.get('foo');
42+
assert.equal(count, 2);
43+
}
44+
45+
['@test caches computation correctly with custom cache keys'](assert) {
46+
let count = 0;
47+
let cache = new Cache(
48+
100,
49+
obj => {
50+
count++;
51+
return obj.value.toUpperCase();
52+
},
53+
obj => obj.key
54+
);
55+
56+
assert.equal(count, 0);
57+
cache.get({ key: 'foo', value: 'foo' });
58+
assert.equal(count, 1);
59+
cache.get({ key: 'bar', value: 'bar' });
60+
assert.equal(count, 2);
61+
cache.get({ key: 'bar', value: 'bar' });
62+
assert.equal(count, 2);
63+
cache.get({ key: 'foo', value: 'foo' });
64+
assert.equal(count, 2);
65+
}
66+
67+
['@test handles undefined value correctly'](assert) {
68+
let count = 0;
69+
let cache = new Cache(100, () => { count++; });
70+
71+
assert.equal(count, 0);
72+
assert.strictEqual(cache.get('foo'), undefined);
73+
assert.equal(count, 1);
74+
assert.strictEqual(cache.get('bar'), undefined);
75+
assert.equal(count, 2);
76+
assert.strictEqual(cache.get('bar'), undefined);
77+
assert.equal(count, 2);
78+
assert.strictEqual(cache.get('foo'), undefined);
79+
assert.equal(count, 2);
80+
}
81+
82+
['@test continues working after reaching cache limit'](assert) {
83+
let cache = new Cache(3, key => key.toUpperCase());
84+
85+
cache.get('a');
86+
cache.get('b');
87+
cache.get('c');
88+
89+
assert.equal(cache.get('d'), 'D');
90+
assert.equal(cache.get('a'), 'A');
91+
assert.equal(cache.get('b'), 'B');
92+
assert.equal(cache.get('c'), 'C');
93+
}
6594
});
6695

67-
QUnit.test('handles undefined value correctly', function(assert) {
68-
let count = 0;
69-
let cache = new Cache(100, () => { count++; });
70-
71-
assert.equal(count, 0);
72-
assert.strictEqual(cache.get('foo'), undefined);
73-
assert.equal(count, 1);
74-
assert.strictEqual(cache.get('bar'), undefined);
75-
assert.equal(count, 2);
76-
assert.strictEqual(cache.get('bar'), undefined);
77-
assert.equal(count, 2);
78-
assert.strictEqual(cache.get('foo'), undefined);
79-
assert.equal(count, 2);
80-
});
81-
82-
QUnit.test('continues working after reaching cache limit', function(assert) {
83-
let cache = new Cache(3, key => key.toUpperCase());
84-
85-
cache.get('a');
86-
cache.get('b');
87-
cache.get('c');
88-
89-
assert.equal(cache.get('d'), 'D');
90-
assert.equal(cache.get('a'), 'A');
91-
assert.equal(cache.get('b'), 'B');
92-
assert.equal(cache.get('c'), 'C');
93-
});

0 commit comments

Comments
 (0)