-
Notifications
You must be signed in to change notification settings - Fork 15
/
ComponentInterpolator.test.js
52 lines (47 loc) · 1.5 KB
/
ComponentInterpolator.test.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
var subjector = require('../test_utils/subjector');
var Subject = subjector(__dirname + '/../ComponentInterpolator');
var React = require('react');
var removeNoise = function(string) {
return string.replace(/<span.*?>|<\/span>/g, '')
.replace(/ data-reactid=".*?"/g, '');
};
describe('ComponentInterpolator', function() {
it('renders', function() {
var subject = Subject({
string: 'Hello World',
wrappers: {}
});
expect(subject.isMounted()).toEqual(true);
expect(subject.getDOMNode().textContent).toEqual('Hello World');
});
it('escapes html in the string', function() {
var subject = Subject({
string: 'My favorite tag is <script />',
wrappers: {}
});
expect(subject.getDOMNode().textContent).toEqual('My favorite tag is <script />');
});
it('interpolates wrapper components', function() {
var subject = Subject({
string: 'Ohai, Jane, click *here* right ***now **please** ***',
wrappers: {
'*': <a href='/'/>,
'**': <i/>,
'***': <b/>
}
});
expect(removeNoise(subject.getDOMNode().innerHTML)).toEqual(
'Ohai, Jane, click <a href="/">here</a> right <b>now <i>please</i> </b>'
);
});
it('interpolates placeholder components', function() {
var subject = Subject({
string: 'Create %{count} new accounts',
wrappers: {},
count: <input/>
});
expect(removeNoise(subject.getDOMNode().innerHTML)).toEqual(
'Create <input> new accounts'
);
});
});