This repository has been archived by the owner on Sep 14, 2019. It is now read-only.
/
currency.spec.js
65 lines (50 loc) · 1.62 KB
/
currency.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
describe('the currency binding', function() {
beforeEach(function() {
this.model = new AModel({price: 0});
this.view = new FixtureView({model: this.model});
_.extend(this.view, {
innerHtml: "<span></span>",
modelBindings: {
'span': {
currency: Backbone.outback.modelRef('price')
}
}
});
});
afterEach(function() {
this.view.remove();
})
it('should update the value of the DOM element when the model changes', function() {
this.view.render();
this.el = this.view.$('#anchor span');
expect(this.el.size() > 0).toBeTruthy();
expect(this.el.text()).toBe('$0.00');
this.model.set({price: 1});
expect(this.el.text()).toBe('$1.00');
});
it('should correctly parse format specifiers', function() {
var match;
match = Backbone.outback.bindingHandlers.currency.parseFormatSpec('prefix9!999?99suffix');
expect(match).toBeDefined();
expect(match[0]).toBe('prefix');
expect(match[1]).toBe('!');
expect(match[2]).toBe('?');
expect(match[3]).toBe('suffix');
});
it('should be configurable', function() {
this.view.modelBindings['span'].currencyOptions = {
format: 'prefix9!999?99suffix'
};
this.view.render();
this.el = this.view.$('#anchor span');
expect(this.el.text()).toBe('prefix0?00suffix');
this.model.set({price: 2485999.95 });
expect(this.el.text()).toBe('prefix2!485!999?95suffix');
});
it('should only show two decimal places', function() {
this.view.render();
this.el = this.view.$('#anchor span');
this.model.set({price: 3.1415 });
expect(this.el.text()).toBe('$3.14');
});
});