Merge branch 'master' into iteration-binding
Showing
2 changed files
with
13 additions
and
6 deletions
... | @@ -85,6 +85,13 @@ describe('Rivets.Binding', function() { | ... | @@ -85,6 +85,13 @@ describe('Rivets.Binding', function() { |
85 | expect(binding.routine).toHaveBeenCalledWith(el, 'awesome sweater'); | 85 | expect(binding.routine).toHaveBeenCalledWith(el, 'awesome sweater'); |
86 | }); | 86 | }); |
87 | 87 | ||
88 | it('calls methods with the object as context', function() { | ||
89 | binding.model = {foo: 'bar'}; | ||
90 | spyOn(binding, 'routine'); | ||
91 | binding.set(function() { return this.foo; }); | ||
92 | expect(binding.routine).toHaveBeenCalledWith(el, binding.model.foo); | ||
93 | }); | ||
94 | |||
88 | describe('on an event binding', function() { | 95 | describe('on an event binding', function() { |
89 | beforeEach(function() { | 96 | beforeEach(function() { |
90 | binding.options.special = 'event'; | 97 | binding.options.special = 'event'; |
... | @@ -110,19 +117,19 @@ describe('Rivets.Binding', function() { | ... | @@ -110,19 +117,19 @@ describe('Rivets.Binding', function() { |
110 | }); | 117 | }); |
111 | }); | 118 | }); |
112 | }); | 119 | }); |
113 | 120 | ||
114 | describe('publish()', function() { | 121 | describe('publish()', function() { |
115 | it("should publish the value of a number input", function() { | 122 | it("should publish the value of a number input", function() { |
116 | numberInput = document.createElement('input'); | 123 | numberInput = document.createElement('input'); |
117 | numberInput.setAttribute('type', 'number'); | 124 | numberInput.setAttribute('type', 'number'); |
118 | numberInput.setAttribute('data-value', 'obj.num'); | 125 | numberInput.setAttribute('data-value', 'obj.num'); |
119 | 126 | ||
120 | view = rivets.bind(numberInput, {obj: {num: 42}}); | 127 | view = rivets.bind(numberInput, {obj: {num: 42}}); |
121 | binding = view.bindings[0]; | 128 | binding = view.bindings[0]; |
122 | model = binding.model; | 129 | model = binding.model; |
123 | 130 | ||
124 | numberInput.value = 42; | 131 | numberInput.value = 42; |
125 | 132 | ||
126 | spyOn(rivets.config.adapter, 'publish'); | 133 | spyOn(rivets.config.adapter, 'publish'); |
127 | binding.publish({target: numberInput}); | 134 | binding.publish({target: numberInput}); |
128 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'num', '42'); | 135 | expect(rivets.config.adapter.publish).toHaveBeenCalledWith(model, 'num', '42'); |
... | @@ -135,7 +142,7 @@ describe('Rivets.Binding', function() { | ... | @@ -135,7 +142,7 @@ describe('Rivets.Binding', function() { |
135 | binding.formatters.push('awesome'); | 142 | binding.formatters.push('awesome'); |
136 | expect(binding.formattedValue('hat')).toBe('awesome hat'); | 143 | expect(binding.formattedValue('hat')).toBe('awesome hat'); |
137 | }); | 144 | }); |
138 | 145 | ||
139 | it('uses formatters on the model', function() { | 146 | it('uses formatters on the model', function() { |
140 | model.modelAwesome = function(value) { return 'model awesome ' + value }; | 147 | model.modelAwesome = function(value) { return 'model awesome ' + value }; |
141 | binding.formatters.push('modelAwesome'); | 148 | binding.formatters.push('modelAwesome'); |
... | @@ -149,7 +156,7 @@ describe('Rivets.Binding', function() { | ... | @@ -149,7 +156,7 @@ describe('Rivets.Binding', function() { |
149 | }; | 156 | }; |
150 | binding.formatters.push('awesome super'); | 157 | binding.formatters.push('awesome super'); |
151 | }); | 158 | }); |
152 | 159 | ||
153 | it('applies the formatter with arguments', function() { | 160 | it('applies the formatter with arguments', function() { |
154 | expect(binding.formattedValue('jacket')).toBe('super awesome jacket'); | 161 | expect(binding.formattedValue('jacket')).toBe('super awesome jacket'); |
155 | }); | 162 | }); | ... | ... |
... | @@ -50,7 +50,7 @@ class Rivets.Binding | ... | @@ -50,7 +50,7 @@ class Rivets.Binding |
50 | else if @options.special is "iteration" | 50 | else if @options.special is "iteration" |
51 | @routine @el, value, @ | 51 | @routine @el, value, @ |
52 | else | 52 | else |
53 | value = value() if value instanceof Function | 53 | value = value.call(@model) if value instanceof Function |
54 | @routine @el, value | 54 | @routine @el, value |
55 | 55 | ||
56 | # Subscribes to the model for changes at the specified keypath. Bi-directional | 56 | # Subscribes to the model for changes at the specified keypath. Bi-directional | ... | ... |
-
Please register or sign in to post a comment