-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathattr-interpolation.js
More file actions
60 lines (46 loc) · 1.83 KB
/
attr-interpolation.js
File metadata and controls
60 lines (46 loc) · 1.83 KB
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
require('reactive-ie8-shims');
var domify = require('domify');
var assert = require('assert');
var reactive = require('../');
describe('attr interpolation', function(){
it('should support initialization', function(){
var el = domify('<a href="/download/{id}"></a>');
var user = { id: '1234' };
var view = reactive(el, user);
assert('/download/1234' == el.getAttribute('href'));
})
it('should ignore whitespace', function(){
var el = domify('<a href="/download/{ id }"></a>');
var user = { id: '1234' };
var view = reactive(el, user);
assert('/download/1234' == el.getAttribute('href'));
})
it('should react to changes', function(){
var el = domify('<a href="/download/{id}"></a>');
var user = { id: '1234' };
var view = reactive(el, user);
assert('/download/1234' == el.getAttribute('href'));
view.set('id', '4321');
assert('/download/4321' == el.getAttribute('href'));
})
it('should support multiple attributes', function(){
var el = domify('<a href="/download/{id}" id="file-{id}">Download {file}</a>');
var user = { id: '1234' };
var view = reactive(el, user);
assert('/download/1234' == el.getAttribute('href'));
assert('file-1234' == el.getAttribute('id'));
view.set('id', '4321');
assert('/download/4321' == el.getAttribute('href'));
assert('file-4321' == el.getAttribute('id'));
})
it('should support multiple properties', function(){
var el = domify('<a href="/download/{id}-{file}"></a>');
var user = { id: '1234', file: 'something' };
var view = reactive(el, user);
assert('/download/1234-something' == el.getAttribute('href'));
view.set('id', '4321');
assert('/download/4321-something' == el.getAttribute('href'));
view.set('file', 'whoop');
assert('/download/4321-whoop' == el.getAttribute('href'));
})
})