Add specs for Rivets.Binding::bind() including edge cases for preloadData and bypass.
Showing
1 changed file
with
35 additions
and
0 deletions
... | @@ -21,6 +21,41 @@ describe('Rivets.Binding', function() { | ... | @@ -21,6 +21,41 @@ describe('Rivets.Binding', function() { |
21 | expect(binding.routine).toBe(rivets.routines.text); | 21 | expect(binding.routine).toBe(rivets.routines.text); |
22 | }); | 22 | }); |
23 | 23 | ||
24 | describe('bind()', function() { | ||
25 | it('subscribes to the model for changes via the adapter', function() { | ||
26 | spyOn(rivets.config.adapter, 'subscribe'); | ||
27 | binding.bind(); | ||
28 | expect(rivets.config.adapter.subscribe).toHaveBeenCalled(); | ||
29 | }); | ||
30 | |||
31 | describe('with preloadData set to true', function() { | ||
32 | beforeEach(function() { | ||
33 | rivets.config.preloadData = true; | ||
34 | }); | ||
35 | |||
36 | it('sets the initial value via the adapter', function() { | ||
37 | spyOn(binding, 'set'); | ||
38 | spyOn(rivets.config.adapter, 'read'); | ||
39 | binding.bind(); | ||
40 | expect(binding.set).toHaveBeenCalled(); | ||
41 | expect(rivets.config.adapter.read).toHaveBeenCalled(); | ||
42 | }); | ||
43 | }); | ||
44 | |||
45 | describe('with the bypass option set to true', function() { | ||
46 | beforeEach(function() { | ||
47 | binding.options.bypass = true; | ||
48 | }); | ||
49 | |||
50 | it('sets the initial value from the model directly', function() { | ||
51 | spyOn(binding, 'set'); | ||
52 | binding.model.name = 'espresso'; | ||
53 | binding.bind(); | ||
54 | expect(binding.set).toHaveBeenCalledWith('espresso'); | ||
55 | }); | ||
56 | }); | ||
57 | }); | ||
58 | |||
24 | describe('set()', function() { | 59 | describe('set()', function() { |
25 | it('performs the binding routine with the supplied value', function() { | 60 | it('performs the binding routine with the supplied value', function() { |
26 | spyOn(binding, 'routine'); | 61 | spyOn(binding, 'routine'); | ... | ... |
-
Please register or sign in to post a comment