@@ -9,102 +9,105 @@ import {
9
9
removeObserver ,
10
10
tagFor
11
11
} from '..' ;
12
+ import { moduleFor , AbstractTestCase } from 'internal-test-helpers' ;
12
13
13
14
let obj , count ;
14
15
15
- QUnit . module ( 'ember-metal/alias' , {
16
+ function incrementCount ( ) {
17
+ count ++ ;
18
+ }
19
+
20
+ moduleFor ( 'ember-metal/alias' , class extends AbstractTestCase {
16
21
beforeEach ( ) {
17
22
obj = { foo : { faz : 'FOO' } } ;
18
23
count = 0 ;
19
- } ,
24
+ }
25
+
20
26
afterEach ( ) {
21
27
obj = null ;
22
28
}
23
- } ) ;
24
29
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
+ }
28
34
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
+ }
33
40
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 ) ;
39
48
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 ) ;
47
51
48
- set ( obj1 , 'foo' , 'FOO' ) ;
49
- assert . equal ( count , 1 ) ;
52
+ removeObserver ( obj1 , 'baz' , incrementCount ) ;
50
53
51
- removeObserver ( obj1 , 'baz' , incrementCount ) ;
54
+ set ( obj1 , 'foo' , 'OOF' ) ;
55
+ assert . equal ( count , 1 ) ;
56
+ }
52
57
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 ) ;
56
62
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 ;
61
64
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 ) ;
63
69
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
68
72
69
- let obj2 = Object . create ( obj1 ) ;
70
- defineProperty ( obj2 , 'baz' , alias ( 'bar' ) ) ; // override baz
73
+ set ( obj2 , 'foo' , 'FOO' ) ;
74
+ assert . equal ( count , 1 ) ;
71
75
72
- set ( obj2 , 'foo' , 'FOO' ) ;
73
- assert . equal ( count , 1 ) ;
76
+ removeObserver ( obj2 , 'baz' , incrementCount ) ;
74
77
75
- removeObserver ( obj2 , 'baz' , incrementCount ) ;
78
+ set ( obj2 , 'foo' , 'OOF' ) ;
79
+ assert . equal ( count , 1 ) ;
80
+ }
76
81
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
+ }
80
89
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
+ }
88
97
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' ) ;
96
101
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 ') ;
100
105
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
+ }
104
108
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
+ }
106
112
} ) ;
107
113
108
- QUnit . test ( 'setting alias on self should fail assertion' , function ( ) {
109
- expectAssertion ( ( ) => defineProperty ( obj , 'bar' , alias ( 'bar' ) ) , 'Setting alias \'bar\' on self' ) ;
110
- } ) ;
0 commit comments