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,6 +83,15 @@ describe('Rivets', function() { ...@@ -83,6 +83,15 @@ describe('Rivets', function() {
83 }); 83 });
84 }); 84 });
85 85
86 describe('Value', function() {
87 it('should set the value of the element', function() {
88 input.setAttribute('data-value', 'data.foo');
89 rivets.bind(input, bindData);
90 expect(input.value).toBe(data.get('foo'));
91 });
92 });
93 });
94
86 describe('Updates', function() { 95 describe('Updates', function() {
87 it('should change the value', function() { 96 it('should change the value', function() {
88 el.setAttribute('data-text', 'data.foo'); 97 el.setAttribute('data-text', 'data.foo');
...@@ -91,5 +100,16 @@ describe('Rivets', function() { ...@@ -91,5 +100,16 @@ describe('Rivets', function() {
91 expect(el).toHaveTheTextContent(data.get('foo')); 100 expect(el).toHaveTheTextContent(data.get('foo'));
92 }); 101 });
93 }); 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 });
94 }); 114 });
95 }); 115 });
......