Skip to content

Commit 2b2e189

Browse files
committed
Update tests to match coffee branch
1 parent d30b429 commit 2b2e189

File tree

6 files changed

+744
-369
lines changed

6 files changed

+744
-369
lines changed

spec/rivets/binders.js

+85-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
describe("Rivets.binders", function() {
2-
var context
2+
var context;
33

44
beforeEach(function() {
55
context = {
66
publish: function() {}
77
}
8-
})
8+
});
99

1010
describe("value", function() {
11-
var el
11+
var el;
1212

1313
beforeEach(function() {
1414
el = document.createElement('input')
15-
})
15+
});
1616

1717
it("unbinds the same bound function", function() {
18-
var boundFn
18+
var boundFn;
1919

2020
sinon.stub(el, 'addEventListener', function(event, fn) {
2121
boundFn = fn
22-
})
22+
});
2323

24-
rivets.binders.value.bind.call(context, el)
24+
rivets.binders.value.bind.call(context, el);
2525

2626
sinon.stub(el, 'removeEventListener', function(event, fn) {
2727
fn.should.equal(boundFn)
28-
})
28+
});
2929

3030
rivets.binders.value.unbind.call(context, el)
3131
})
32-
})
32+
});
3333

3434
describe("each-*", function() {
3535
var fragment;
@@ -56,34 +56,22 @@ describe("Rivets.binders", function() {
5656

5757
it("reflects changes to the model into the DOM", function() {
5858
var view = rivets.bind(fragment, model);
59-
Should(fragment.childNodes[1].innerText).be.exactly("0");
59+
Should(fragment.childNodes[1].textContent).be.exactly("0");
6060

6161
model.items[0].val = "howdy";
62-
Should(fragment.childNodes[1].innerText).be.exactly("howdy");
62+
Should(fragment.childNodes[1].textContent).be.exactly("howdy");
6363
});
6464

6565
it("reflects changes to the model into the DOM after unbind/bind", function() {
6666
var view = rivets.bind(fragment, model);
67-
Should(fragment.childNodes[1].innerText).be.exactly("0");
67+
Should(fragment.childNodes[1].textContent).be.exactly("0");
6868

6969
view.unbind();
7070
view.bind();
7171
model.items[0].val = "howdy";
72-
Should(fragment.childNodes[1].innerText).be.exactly("howdy");
72+
Should(fragment.childNodes[1].textContent).be.exactly("howdy");
7373
});
7474

75-
it("lets you pop an item", function() {
76-
var view = rivets.bind(fragment, model);
77-
var originalLength = model.items.length;
78-
79-
// one child for each element in the model plus 1 for the comment placeholder
80-
Should(fragment.childNodes.length).be.exactly(model.items.length + 1);
81-
82-
model.items.pop();
83-
Should(model.items.length).be.exactly(originalLength - 1);
84-
Should(fragment.childNodes.length).be.exactly(model.items.length + 1);
85-
})
86-
8775
it("lets you push an item", function() {
8876
var view = rivets.bind(fragment, model);
8977
var originalLength = model.items.length;
@@ -112,6 +100,34 @@ describe("Rivets.binders", function() {
112100
});
113101
});
114102

103+
describe("nested-each-*", function() {
104+
var fragment;
105+
var el;
106+
var nestedEl;
107+
var model;
108+
109+
beforeEach(function() {
110+
fragment = document.createDocumentFragment();
111+
el = document.createElement("span");
112+
el.setAttribute("rv-each-item", "items");
113+
nestedEl = document.createElement("span");
114+
nestedEl.setAttribute("rv-each-nested", "item.val");
115+
nestedEl.textContent = "{%item%}-{%nested%}";
116+
el.appendChild(nestedEl);
117+
fragment.appendChild(el);
118+
119+
model = { items: [{val: [{val: 0},{val: 1}]},{val: [{val: 2},{val: 3}]},{val: [{val: 4},{val: 5}]}] };
120+
});
121+
122+
it.skip("lets you get all the indexes", function() {
123+
var view = rivets.bind(el, model);
124+
125+
Should(fragment.childNodes[1].childNodes[1].textContent).be.exactly('0-0');
126+
Should(fragment.childNodes[1].childNodes[2].textContent).be.exactly('0-1');
127+
Should(fragment.childNodes[2].childNodes[2].textContent).be.exactly('1-1');
128+
});
129+
});
130+
115131
describe("if", function() {
116132
var fragment;
117133
var el;
@@ -183,5 +199,49 @@ describe("Rivets.binders", function() {
183199
// 1 for the comment placeholder
184200
Should(fragment.childNodes.length).be.exactly(1);
185201
});
202+
203+
it("rebindes nested if", function() {
204+
var nestedEl = document.createElement("div");
205+
nestedEl.setAttribute("rv-if", "data.showNested");
206+
nestedEl.innerHTML = "{ data.countNested }";
207+
el.appendChild(nestedEl);
208+
209+
var view = rivets.bind(fragment, model);
210+
211+
model.data.countNested = "1";
212+
model.data.showNested = true;
213+
Should(nestedEl.innerHTML).be.exactly("1");
214+
model.data.show = false;
215+
model.data.show = true;
216+
model.data.countNested = "42";
217+
218+
Should(nestedEl.innerHTML).be.exactly("42");
219+
});
220+
});
221+
222+
describe("Custom binder with no attribute value", function() {
223+
var el, model;
224+
rivets.binders["custom-binder"] = function(el, value) {
225+
el.innerHTML = "received " + value;
226+
};
227+
beforeEach(function() {
228+
fragment = document.createDocumentFragment();
229+
el = document.createElement("div");
230+
231+
fragment.appendChild(el);
232+
233+
model = {};
234+
});
235+
236+
it("receives undefined when html attribute is not specified", function() {
237+
el.innerHTML = "<div rv-custom-binder></div>";
238+
var view = rivets.bind(fragment, model);
239+
Should(el.children[0].innerHTML).be.exactly('received undefined');
240+
});
241+
it("receives undefined when html attribute is not specified", function() {
242+
el.innerHTML = "<div rv-custom-binder=''></div>";
243+
var view = rivets.bind(fragment, model);
244+
Should(el.children[0].innerHTML).be.exactly('received undefined');
245+
});
186246
});
187247
});

0 commit comments

Comments
 (0)