Make sure use a different interface for the primary adapter being used in the function specs.
Showing
1 changed file
with
37 additions
and
28 deletions
... | @@ -2,18 +2,13 @@ describe('Functional', function() { | ... | @@ -2,18 +2,13 @@ describe('Functional', function() { |
2 | var data, bindData, el, input; | 2 | var data, bindData, el, input; |
3 | 3 | ||
4 | beforeEach(function() { | 4 | beforeEach(function() { |
5 | data = new Data({foo: 'bar', items: [{name: 'a'}, {name: 'b'}]}); | 5 | adapter = { |
6 | bindData = {data: data}; | ||
7 | el = document.createElement('div'); | ||
8 | input = document.createElement('input'); | ||
9 | input.setAttribute('type', 'text'); | ||
10 | |||
11 | rivets.configure({ | ||
12 | preloadData: true, | ||
13 | adapter: { | ||
14 | subscribe: function(obj, keypath, callback) { | 6 | subscribe: function(obj, keypath, callback) { |
15 | obj.on(keypath, callback); | 7 | obj.on(keypath, callback); |
16 | }, | 8 | }, |
9 | unsubscribe: function(obj, keypath, callback) { | ||
10 | obj.off(keypath, callback); | ||
11 | }, | ||
17 | read: function(obj, keypath) { | 12 | read: function(obj, keypath) { |
18 | return obj.get(keypath); | 13 | return obj.get(keypath); |
19 | }, | 14 | }, |
... | @@ -22,14 +17,27 @@ describe('Functional', function() { | ... | @@ -22,14 +17,27 @@ describe('Functional', function() { |
22 | attributes[keypath] = value; | 17 | attributes[keypath] = value; |
23 | obj.set(attributes); | 18 | obj.set(attributes); |
24 | } | 19 | } |
25 | } | 20 | }; |
21 | |||
22 | rivets.adapters[':'] = adapter; | ||
23 | rivets.configure({preloadData: true}); | ||
24 | |||
25 | data = new Data({ | ||
26 | foo: 'bar', | ||
27 | items: [{name: 'a'}, {name: 'b'}] | ||
26 | }); | 28 | }); |
29 | |||
30 | bindData = {data: data}; | ||
31 | |||
32 | el = document.createElement('div'); | ||
33 | input = document.createElement('input'); | ||
34 | input.setAttribute('type', 'text'); | ||
27 | }); | 35 | }); |
28 | 36 | ||
29 | describe('Adapter', function() { | 37 | describe('Adapter', function() { |
30 | it('should read the initial value', function() { | 38 | it('should read the initial value', function() { |
31 | spyOn(data, 'get'); | 39 | spyOn(data, 'get'); |
32 | el.setAttribute('data-text', 'data.foo'); | 40 | el.setAttribute('data-text', 'data:foo'); |
33 | rivets.bind(el, bindData); | 41 | rivets.bind(el, bindData); |
34 | expect(data.get).toHaveBeenCalledWith('foo'); | 42 | expect(data.get).toHaveBeenCalledWith('foo'); |
35 | }); | 43 | }); |
... | @@ -37,14 +45,14 @@ describe('Functional', function() { | ... | @@ -37,14 +45,14 @@ describe('Functional', function() { |
37 | it('should read the initial value unless preloadData is false', function() { | 45 | it('should read the initial value unless preloadData is false', function() { |
38 | rivets.configure({preloadData: false}); | 46 | rivets.configure({preloadData: false}); |
39 | spyOn(data, 'get'); | 47 | spyOn(data, 'get'); |
40 | el.setAttribute('data-value', 'data.foo'); | 48 | el.setAttribute('data-value', 'data:foo'); |
41 | rivets.bind(el, bindData); | 49 | rivets.bind(el, bindData); |
42 | expect(data.get).not.toHaveBeenCalled(); | 50 | expect(data.get).not.toHaveBeenCalled(); |
43 | }); | 51 | }); |
44 | 52 | ||
45 | it('should subscribe to updates', function() { | 53 | it('should subscribe to updates', function() { |
46 | spyOn(data, 'on'); | 54 | spyOn(data, 'on'); |
47 | el.setAttribute('data-value', 'data.foo'); | 55 | el.setAttribute('data-value', 'data:foo'); |
48 | rivets.bind(el, bindData); | 56 | rivets.bind(el, bindData); |
49 | expect(data.on).toHaveBeenCalled(); | 57 | expect(data.on).toHaveBeenCalled(); |
50 | }); | 58 | }); |
... | @@ -53,13 +61,14 @@ describe('Functional', function() { | ... | @@ -53,13 +61,14 @@ describe('Functional', function() { |
53 | describe('Binds', function() { | 61 | describe('Binds', function() { |
54 | describe('Text', function() { | 62 | describe('Text', function() { |
55 | it('should set the text content of the element', function() { | 63 | it('should set the text content of the element', function() { |
56 | el.setAttribute('data-text', 'data.foo'); | 64 | el.setAttribute('data-text', 'data:foo'); |
57 | rivets.bind(el, bindData); | 65 | rivets.bind(el, bindData); |
66 | debugger | ||
58 | expect(el.textContent || el.innerText).toBe(data.get('foo')); | 67 | expect(el.textContent || el.innerText).toBe(data.get('foo')); |
59 | }); | 68 | }); |
60 | 69 | ||
61 | it('should correctly handle HTML in the content', function() { | 70 | it('should correctly handle HTML in the content', function() { |
62 | el.setAttribute('data-text', 'data.foo'); | 71 | el.setAttribute('data-text', 'data:foo'); |
63 | value = '<b>Fail</b>'; | 72 | value = '<b>Fail</b>'; |
64 | data.set({foo: value}); | 73 | data.set({foo: value}); |
65 | rivets.bind(el, bindData); | 74 | rivets.bind(el, bindData); |
... | @@ -69,13 +78,13 @@ describe('Functional', function() { | ... | @@ -69,13 +78,13 @@ describe('Functional', function() { |
69 | 78 | ||
70 | describe('HTML', function() { | 79 | describe('HTML', function() { |
71 | it('should set the html content of the element', function() { | 80 | it('should set the html content of the element', function() { |
72 | el.setAttribute('data-html', 'data.foo'); | 81 | el.setAttribute('data-html', 'data:foo'); |
73 | rivets.bind(el, bindData); | 82 | rivets.bind(el, bindData); |
74 | expect(el).toHaveTheTextContent(data.get('foo')); | 83 | expect(el).toHaveTheTextContent(data.get('foo')); |
75 | }); | 84 | }); |
76 | 85 | ||
77 | it('should correctly handle HTML in the content', function() { | 86 | it('should correctly handle HTML in the content', function() { |
78 | el.setAttribute('data-html', 'data.foo'); | 87 | el.setAttribute('data-html', 'data:foo'); |
79 | value = '<b>Fail</b>'; | 88 | value = '<b>Fail</b>'; |
80 | data.set({foo: value}); | 89 | data.set({foo: value}); |
81 | rivets.bind(el, bindData); | 90 | rivets.bind(el, bindData); |
... | @@ -85,7 +94,7 @@ describe('Functional', function() { | ... | @@ -85,7 +94,7 @@ describe('Functional', function() { |
85 | 94 | ||
86 | describe('Value', function() { | 95 | describe('Value', function() { |
87 | it('should set the value of the element', function() { | 96 | it('should set the value of the element', function() { |
88 | input.setAttribute('data-value', 'data.foo'); | 97 | input.setAttribute('data-value', 'data:foo'); |
89 | rivets.bind(input, bindData); | 98 | rivets.bind(input, bindData); |
90 | expect(input.value).toBe(data.get('foo')); | 99 | expect(input.value).toBe(data.get('foo')); |
91 | }); | 100 | }); |
... | @@ -93,8 +102,8 @@ describe('Functional', function() { | ... | @@ -93,8 +102,8 @@ describe('Functional', function() { |
93 | 102 | ||
94 | describe('Multiple', function() { | 103 | describe('Multiple', function() { |
95 | it('should bind a list of multiple elements', function() { | 104 | it('should bind a list of multiple elements', function() { |
96 | el.setAttribute('data-html', 'data.foo'); | 105 | el.setAttribute('data-html', 'data:foo'); |
97 | input.setAttribute('data-value', 'data.foo'); | 106 | input.setAttribute('data-value', 'data:foo'); |
98 | rivets.bind([el, input], bindData); | 107 | rivets.bind([el, input], bindData); |
99 | expect(el).toHaveTheTextContent(data.get('foo')); | 108 | expect(el).toHaveTheTextContent(data.get('foo')); |
100 | expect(input.value).toBe(data.get('foo')); | 109 | expect(input.value).toBe(data.get('foo')); |
... | @@ -106,7 +115,7 @@ describe('Functional', function() { | ... | @@ -106,7 +115,7 @@ describe('Functional', function() { |
106 | list = document.createElement('ul'); | 115 | list = document.createElement('ul'); |
107 | el.appendChild(list); | 116 | el.appendChild(list); |
108 | listItem = document.createElement('li'); | 117 | listItem = document.createElement('li'); |
109 | listItem.setAttribute('data-each-item', 'data.items'); | 118 | listItem.setAttribute('data-each-item', 'data:items'); |
110 | list.appendChild(listItem); | 119 | list.appendChild(listItem); |
111 | }); | 120 | }); |
112 | 121 | ||
... | @@ -133,9 +142,9 @@ describe('Functional', function() { | ... | @@ -133,9 +142,9 @@ describe('Functional', function() { |
133 | 142 | ||
134 | it('should allow binding to the iterated item as well as any parent contexts', function() { | 143 | it('should allow binding to the iterated item as well as any parent contexts', function() { |
135 | span1 = document.createElement('span'); | 144 | span1 = document.createElement('span'); |
136 | span1.setAttribute('data-text', 'item:name') | 145 | span1.setAttribute('data-text', 'item.name') |
137 | span2 = document.createElement('span'); | 146 | span2 = document.createElement('span'); |
138 | span2.setAttribute('data-text', 'data.foo') | 147 | span2.setAttribute('data-text', 'data:foo') |
139 | listItem.appendChild(span1); | 148 | listItem.appendChild(span1); |
140 | listItem.appendChild(span2); | 149 | listItem.appendChild(span2); |
141 | 150 | ||
... | @@ -145,8 +154,8 @@ describe('Functional', function() { | ... | @@ -145,8 +154,8 @@ describe('Functional', function() { |
145 | }); | 154 | }); |
146 | 155 | ||
147 | it('should allow binding to the iterated element directly', function() { | 156 | it('should allow binding to the iterated element directly', function() { |
148 | listItem.setAttribute('data-text', 'item:name'); | 157 | listItem.setAttribute('data-text', 'item.name'); |
149 | listItem.setAttribute('data-class', 'data.foo'); | 158 | listItem.setAttribute('data-class', 'data:foo'); |
150 | rivets.bind(el, bindData); | 159 | rivets.bind(el, bindData); |
151 | expect(el.getElementsByTagName('li')[0]).toHaveTheTextContent('a'); | 160 | expect(el.getElementsByTagName('li')[0]).toHaveTheTextContent('a'); |
152 | expect(el.getElementsByTagName('li')[0].className).toBe('bar'); | 161 | expect(el.getElementsByTagName('li')[0].className).toBe('bar'); |
... | @@ -160,7 +169,7 @@ describe('Functional', function() { | ... | @@ -160,7 +169,7 @@ describe('Functional', function() { |
160 | list.appendChild(lastItem); | 169 | list.appendChild(lastItem); |
161 | list.insertBefore(firstItem, listItem); | 170 | list.insertBefore(firstItem, listItem); |
162 | 171 | ||
163 | listItem.setAttribute('data-text', 'item:name'); | 172 | listItem.setAttribute('data-text', 'item.name'); |
164 | 173 | ||
165 | rivets.bind(el, bindData); | 174 | rivets.bind(el, bindData); |
166 | expect(el.getElementsByTagName('li')[0]).toHaveTheTextContent('first'); | 175 | expect(el.getElementsByTagName('li')[0]).toHaveTheTextContent('first'); |
... | @@ -174,7 +183,7 @@ describe('Functional', function() { | ... | @@ -174,7 +183,7 @@ describe('Functional', function() { |
174 | 183 | ||
175 | describe('Updates', function() { | 184 | describe('Updates', function() { |
176 | it('should change the value', function() { | 185 | it('should change the value', function() { |
177 | el.setAttribute('data-text', 'data.foo'); | 186 | el.setAttribute('data-text', 'data:foo'); |
178 | rivets.bind(el, bindData); | 187 | rivets.bind(el, bindData); |
179 | data.set({foo: 'some new value'}); | 188 | data.set({foo: 'some new value'}); |
180 | expect(el).toHaveTheTextContent(data.get('foo')); | 189 | expect(el).toHaveTheTextContent(data.get('foo')); |
... | @@ -183,7 +192,7 @@ describe('Functional', function() { | ... | @@ -183,7 +192,7 @@ describe('Functional', function() { |
183 | 192 | ||
184 | describe('Input', function() { | 193 | describe('Input', function() { |
185 | it('should update the model value', function() { | 194 | it('should update the model value', function() { |
186 | input.setAttribute('data-value', 'data.foo'); | 195 | input.setAttribute('data-value', 'data:foo'); |
187 | rivets.bind(input, bindData); | 196 | rivets.bind(input, bindData); |
188 | input.value = 'some new value'; | 197 | input.value = 'some new value'; |
189 | var event = document.createEvent('HTMLEvents') | 198 | var event = document.createEvent('HTMLEvents') | ... | ... |
-
Please register or sign in to post a comment