Instead of configuring the adapter, stub out the default adapter instead in the binding spec.
Showing
1 changed file
with
26 additions
and
26 deletions
... | @@ -2,19 +2,19 @@ describe('Rivets.Binding', function() { | ... | @@ -2,19 +2,19 @@ describe('Rivets.Binding', function() { |
2 | var model, el, view, binding, opts; | 2 | var model, el, view, binding, opts; |
3 | 3 | ||
4 | beforeEach(function() { | 4 | beforeEach(function() { |
5 | rivets.configure({ | 5 | adapter = { |
6 | adapter: { | ||
7 | subscribe: function() {}, | 6 | subscribe: function() {}, |
8 | unsubscribe: function() {}, | 7 | unsubscribe: function() {}, |
9 | read: function() {}, | 8 | read: function() { return {} }, |
10 | publish: function() {} | 9 | publish: function() {} |
11 | } | 10 | }; |
12 | }); | 11 | |
12 | rivets.adapters['.'] = adapter; | ||
13 | 13 | ||
14 | el = document.createElement('div'); | 14 | el = document.createElement('div'); |
15 | el.setAttribute('data-text', 'obj.name'); | 15 | el.setAttribute('data-text', 'obj.name'); |
16 | opts = {}; | 16 | |
17 | view = rivets.bind(el, {obj: {}}, opts); | 17 | view = rivets.bind(el, {obj: {}}); |
18 | binding = view.bindings[0]; | 18 | binding = view.bindings[0]; |
19 | model = binding.model; | 19 | model = binding.model; |
20 | }); | 20 | }); |
... | @@ -25,9 +25,9 @@ describe('Rivets.Binding', function() { | ... | @@ -25,9 +25,9 @@ describe('Rivets.Binding', function() { |
25 | 25 | ||
26 | describe('bind()', function() { | 26 | describe('bind()', function() { |
27 | it('subscribes to the model for changes via the adapter', function() { | 27 | it('subscribes to the model for changes via the adapter', function() { |
28 | spyOn(rivets.config.adapter, 'subscribe'); | 28 | spyOn(adapter, 'subscribe'); |
29 | binding.bind(); | 29 | binding.bind(); |
30 | expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'name', binding.sync); | 30 | expect(adapter.subscribe).toHaveBeenCalledWith(model, 'name', binding.sync); |
31 | }); | 31 | }); |
32 | 32 | ||
33 | it("calls the binder's bind method if one exists", function() { | 33 | it("calls the binder's bind method if one exists", function() { |
... | @@ -48,9 +48,9 @@ describe('Rivets.Binding', function() { | ... | @@ -48,9 +48,9 @@ describe('Rivets.Binding', function() { |
48 | 48 | ||
49 | it('sets the initial value via the adapter', function() { | 49 | it('sets the initial value via the adapter', function() { |
50 | spyOn(binding, 'set'); | 50 | spyOn(binding, 'set'); |
51 | spyOn(rivets.config.adapter, 'read'); | 51 | spyOn(adapter, 'read'); |
52 | binding.bind(); | 52 | binding.bind(); |
53 | expect(rivets.config.adapter.read).toHaveBeenCalledWith(model, 'name'); | 53 | expect(adapter.read).toHaveBeenCalledWith(model, 'name'); |
54 | expect(binding.set).toHaveBeenCalled(); | 54 | expect(binding.set).toHaveBeenCalled(); |
55 | }); | 55 | }); |
56 | }); | 56 | }); |
... | @@ -85,10 +85,10 @@ describe('Rivets.Binding', function() { | ... | @@ -85,10 +85,10 @@ describe('Rivets.Binding', function() { |
85 | }); | 85 | }); |
86 | 86 | ||
87 | it('sets up observers on the dependant attributes', function() { | 87 | it('sets up observers on the dependant attributes', function() { |
88 | spyOn(rivets.config.adapter, 'subscribe'); | 88 | spyOn(adapter, 'subscribe'); |
89 | binding.bind(); | 89 | binding.bind(); |
90 | expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'fname', binding.sync); | 90 | expect(adapter.subscribe).toHaveBeenCalledWith(model, 'fname', binding.sync); |
91 | expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'lname', binding.sync); | 91 | expect(adapter.subscribe).toHaveBeenCalledWith(model, 'lname', binding.sync); |
92 | }); | 92 | }); |
93 | }); | 93 | }); |
94 | }); | 94 | }); |
... | @@ -158,9 +158,9 @@ describe('Rivets.Binding', function() { | ... | @@ -158,9 +158,9 @@ describe('Rivets.Binding', function() { |
158 | 158 | ||
159 | numberInput.value = 42; | 159 | numberInput.value = 42; |
160 | 160 | ||
161 | spyOn(rivets.config.adapter, 'publish'); | 161 | spyOn(adapter, 'publish'); |
162 | binding.publish({target: numberInput}); | 162 | binding.publish({target: numberInput}); |
163 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'num', '42'); | 163 | expect(adapter.publish).toHaveBeenCalledWith(model, 'num', '42'); |
164 | }); | 164 | }); |
165 | }); | 165 | }); |
166 | 166 | ||
... | @@ -191,9 +191,9 @@ describe('Rivets.Binding', function() { | ... | @@ -191,9 +191,9 @@ describe('Rivets.Binding', function() { |
191 | 191 | ||
192 | numberInput.value = 42; | 192 | numberInput.value = 42; |
193 | 193 | ||
194 | spyOn(rivets.config.adapter, 'publish'); | 194 | spyOn(adapter, 'publish'); |
195 | binding.publish({target: numberInput}); | 195 | binding.publish({target: numberInput}); |
196 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'num', 'awesome 42'); | 196 | expect(adapter.publish).toHaveBeenCalledWith(model, 'num', 'awesome 42'); |
197 | }); | 197 | }); |
198 | 198 | ||
199 | it("should format a value in both directions", function() { | 199 | it("should format a value in both directions", function() { |
... | @@ -209,10 +209,10 @@ describe('Rivets.Binding', function() { | ... | @@ -209,10 +209,10 @@ describe('Rivets.Binding', function() { |
209 | binding = view.bindings[0]; | 209 | binding = view.bindings[0]; |
210 | model = binding.model; | 210 | model = binding.model; |
211 | 211 | ||
212 | spyOn(rivets.config.adapter, 'publish'); | 212 | spyOn(adapter, 'publish'); |
213 | valueInput.value = 'charles'; | 213 | valueInput.value = 'charles'; |
214 | binding.publish({target: valueInput}); | 214 | binding.publish({target: valueInput}); |
215 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'name', 'awesome charles'); | 215 | expect(adapter.publish).toHaveBeenCalledWith(model, 'name', 'awesome charles'); |
216 | 216 | ||
217 | spyOn(binding.binder, 'routine'); | 217 | spyOn(binding.binder, 'routine'); |
218 | binding.set('fred'); | 218 | binding.set('fred'); |
... | @@ -229,10 +229,10 @@ describe('Rivets.Binding', function() { | ... | @@ -229,10 +229,10 @@ describe('Rivets.Binding', function() { |
229 | binding = view.bindings[0]; | 229 | binding = view.bindings[0]; |
230 | model = binding.model; | 230 | model = binding.model; |
231 | 231 | ||
232 | spyOn(rivets.config.adapter, 'publish'); | 232 | spyOn(adapter, 'publish'); |
233 | valueInput.value = 'charles'; | 233 | valueInput.value = 'charles'; |
234 | binding.publish({target: valueInput}); | 234 | binding.publish({target: valueInput}); |
235 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'name', 'charles'); | 235 | expect(adapter.publish).toHaveBeenCalledWith(model, 'name', 'charles'); |
236 | 236 | ||
237 | spyOn(binding.binder, 'routine'); | 237 | spyOn(binding.binder, 'routine'); |
238 | binding.set('fred'); | 238 | binding.set('fred'); |
... | @@ -262,10 +262,10 @@ describe('Rivets.Binding', function() { | ... | @@ -262,10 +262,10 @@ describe('Rivets.Binding', function() { |
262 | binding.set('fred'); | 262 | binding.set('fred'); |
263 | expect(binding.binder.routine).toHaveBeenCalledWith(valueInput, 'fred is awesome totally'); | 263 | expect(binding.binder.routine).toHaveBeenCalledWith(valueInput, 'fred is awesome totally'); |
264 | 264 | ||
265 | spyOn(rivets.config.adapter, 'publish'); | 265 | spyOn(adapter, 'publish'); |
266 | valueInput.value = 'fred'; | 266 | valueInput.value = 'fred'; |
267 | binding.publish({target: valueInput}); | 267 | binding.publish({target: valueInput}); |
268 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'name', 'fred totally is awesome'); | 268 | expect(adapter.publish).toHaveBeenCalledWith(model, 'name', 'fred totally is awesome'); |
269 | }); | 269 | }); |
270 | 270 | ||
271 | it("binders in a chain should be skipped if they're not there", function() { | 271 | it("binders in a chain should be skipped if they're not there", function() { |
... | @@ -290,10 +290,10 @@ describe('Rivets.Binding', function() { | ... | @@ -290,10 +290,10 @@ describe('Rivets.Binding', function() { |
290 | binding.set('fred'); | 290 | binding.set('fred'); |
291 | expect(binding.binder.routine).toHaveBeenCalledWith(valueInput, 'fred is awesome totally'); | 291 | expect(binding.binder.routine).toHaveBeenCalledWith(valueInput, 'fred is awesome totally'); |
292 | 292 | ||
293 | spyOn(rivets.config.adapter, 'publish'); | 293 | spyOn(adapter, 'publish'); |
294 | valueInput.value = 'fred'; | 294 | valueInput.value = 'fred'; |
295 | binding.publish({target: valueInput}); | 295 | binding.publish({target: valueInput}); |
296 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'name', 'fred totally is radical'); | 296 | expect(adapter.publish).toHaveBeenCalledWith(model, 'name', 'fred totally is radical'); |
297 | }); | 297 | }); |
298 | 298 | ||
299 | }); | 299 | }); | ... | ... |
-
Please register or sign in to post a comment