9b284cf9 by Nicklas Ansman Giertz

Add some more tests

1 parent 8739f9af
1
2
3 describe('Rivets', function() { 1 describe('Rivets', function() {
4 var data, bindData, el; 2 var data, bindData, el, input;
5 3
6 beforeEach(function() { 4 beforeEach(function() {
7 data = new Data({foo: 'bar'}); 5 data = new Data({foo: 'bar'});
8 bindData = {data: data}; 6 bindData = {data: data};
9 el = document.createElement('div'); 7 el = document.createElement('div');
8 input = document.createElement('input');
9 input.setAttribute('type', 'text');
10 10
11 rivets.configure({ 11 rivets.configure({
12 preloadData: true, 12 preloadData: true,
...@@ -83,13 +83,33 @@ describe('Rivets', function() { ...@@ -83,13 +83,33 @@ describe('Rivets', function() {
83 }); 83 });
84 }); 84 });
85 85
86 describe('Updates', function() { 86 describe('Value', function() {
87 it('should change the value', function() { 87 it('should set the value of the element', function() {
88 el.setAttribute('data-text', 'data.foo'); 88 input.setAttribute('data-value', 'data.foo');
89 rivets.bind(el, bindData); 89 rivets.bind(input, bindData);
90 data.set({foo: 'some new value'}); 90 expect(input.value).toBe(data.get('foo'));
91 expect(el).toHaveTheTextContent(data.get('foo'));
92 }); 91 });
93 }); 92 });
94 }); 93 });
94
95 describe('Updates', function() {
96 it('should change the value', function() {
97 el.setAttribute('data-text', 'data.foo');
98 rivets.bind(el, bindData);
99 data.set({foo: 'some new value'});
100 expect(el).toHaveTheTextContent(data.get('foo'));
101 });
102 });
103
104 describe('Input', function() {
105 it('should update the model value', function() {
106 input.setAttribute('data-value', 'data.foo');
107 rivets.bind(input, bindData);
108 input.value = 'some new value';
109 var event = document.createEvent('HTMLEvents')
110 event.initEvent('change', true, true);
111 input.dispatchEvent(event);
112 expect(input.value).toBe(data.get('foo'));
113 });
114 });
95 }); 115 });
......