Skip to content

Commit

Permalink
add failing test for #649
Browse files Browse the repository at this point in the history
  • Loading branch information
benadamstyles committed Aug 7, 2016
1 parent a609bd8 commit e64440f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/rivets/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,40 @@ describe('Rivets.Binding', function() {
binding.binder.routine.calledWith(valueInput, 'fred is awesome').should.be.true
})

it("should resolve formatter arguments to their values", function() {
rivets.formatters.withArguments = {
publish: function(value, arg1, arg2) {
return value + ':' + arg1 + ':' + arg2
},
read: function(value, arg1, arg2) {
return value + '-' + arg1 + '-' + arg2
}
}

valueInput = document.createElement('input')
valueInput.setAttribute('type', 'text')
valueInput.setAttribute('data-value', "obj.name | withArguments config.age 'male'")

view = rivets.bind(valueInput, {
obj: {
name: 'nothing'
},
config: {
age: 50
}
})

binding = view.bindings[0]
model = binding.model

valueInput.value = 'bobby'
binding.publish({target: valueInput})
adapter.set.calledWith(model, 'name', 'bobby:50:male').should.be.true

binding.set('andy')
binding.binder.routine.calledWith(valueInput, 'andy-50-male').should.be.true
})

it("should not fail or format if the specified binding function doesn't exist", function() {
rivets.formatters.awesome = { }
valueInput = document.createElement('input')
Expand Down

0 comments on commit e64440f

Please sign in to comment.