forked from abramz/gulp-render-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
84 lines (73 loc) · 2.37 KB
/
test.js
File metadata and controls
84 lines (73 loc) · 2.37 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* global it */
'use strict';
var assert = require('assert');
var gutil = require('gulp-util');
var render = require('./');
it('should render valid React components to string', function (cb) {
var stream = render('string');
stream.on('data', function (file) {
var extensionPattern = /.*?\.html/;
var contentsPattern = /<ul data-reactid=".*?" data-react-checksum=".*?"><li data-reactid=".*?"><span data-reactid=".*?">some<\/span><span data-reactid=".*?"> : <\/span><span data-reactid=".*?">prop<\/span><\/li><\/ul>/;
assert(extensionPattern.test(file.path));
assert(contentsPattern.test(file.contents.toString()));
cb();
});
stream.write(new gutil.File({
base: __dirname,
path: __dirname + '/fixtures/validComponent.jsx'
}));
});
it('should render valid React components to static markup', function (cb) {
var stream = render('markup');
stream.on('data', function (file) {
var pattern = /<ul><li>some : prop<\/li><\/ul>/;
assert(pattern.test(file.contents.toString()));
cb();
});
stream.write(new gutil.File({
base: __dirname,
path: __dirname + '/fixtures/validComponent.jsx'
}));
});
it('should render provided props', function (cb) {
var stream = render('markup', {
a: 'prop',
b: 'thing',
c: 'stuff'
});
stream.on('data', function (file) {
var pattern = /<ul><li>a : prop<\/li><li>b : thing<\/li><li>c : stuff<\/li><li>some : prop<\/li><\/ul>/;
assert(pattern.test(file.contents.toString()));
cb();
});
stream.write(new gutil.File({
base: __dirname,
path: __dirname + '/fixtures/validComponent.jsx'
}));
});
it('should render when given js', function (cb) {
var stream = render('markup');
stream.on('data', function (file) {
var pattern = /<ul><li>some : prop<\/li><\/ul>/;
assert(pattern.test(file.contents.toString()));
cb();
});
stream.write(new gutil.File({
base: __dirname,
path: __dirname + '/fixtures/anotherValidComponent.js'
}));
});
it('should have an error if `type` is not `string` or `markup`', function (cb) {
assert.throws(render, gutil.PluginError);
cb();
});
it('should emit an error for invalid React components', function (cb) {
var stream = render('string');
stream.on('error', function () {
cb();
});
stream.write(new gutil.File({
base: __dirname,
path: __dirname + '/fixtures/invalidComponent.jsx'
}));
});