-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtemplate-file-info-test.js
More file actions
58 lines (47 loc) · 2 KB
/
template-file-info-test.js
File metadata and controls
58 lines (47 loc) · 2 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
var assertDiff = require('assert-diff');
var fixturify = require('fixturify');
var fse = require('fs-extra');
var Migrator = require('../../../lib');
assertDiff.options.strict = true;
describe('template-file-info', function() {
describe('detectRenderableInvocations', function() {
var tmpPath = 'tmp/detect-templates';
beforeEach(function() {
fse.mkdirsSync(tmpPath);
});
afterEach(function() {
fse.removeSync(tmpPath);
});
function confirmDetectsRenderables(templateSnippet, expectedRenderables) {
it('`' + templateSnippet + '` should include ' + expectedRenderables, function() {
fixturify.writeSync(tmpPath, {
app: {
templates: {
'post.hbs': templateSnippet
}
}
});
var engine = new Migrator({
projectRoot: tmpPath
});
var file = engine.fileInfoFor('app/templates/post.hbs');
file.detectRenderableInvocations();
assertDiff.deepEqual(file.renderablesInvoked, expectedRenderables);
});
}
// components
confirmDetectsRenderables('{{#foo-bar}}{{/foo-bar}}', ['foo-bar']);
confirmDetectsRenderables('{{foo-bar derp="blammo"}}', ['foo-bar']);
confirmDetectsRenderables('<div>{{#foo-bar}}{{huz-zah blah="lolol"}}{{/foo-bar}}</div>', ['foo-bar', 'huz-zah']);
confirmDetectsRenderables('{{yield (hash foo=(build-thing) bar=(component "bar-baz"))}}', ['yield', 'hash', 'build-thing', 'component', 'bar-baz']);
confirmDetectsRenderables('{{component "foo-bar"}}', ['component', 'foo-bar']);
// helpers
confirmDetectsRenderables('{{t "some thing"}}', ['t']);
confirmDetectsRenderables('{{t "some thing"}}{{t "whopdee doo"}}', ['t']);
confirmDetectsRenderables('{{derp blah="haha"}}', ['derp']);
confirmDetectsRenderables('<div data-foo={{derp blah="haha"}}></div>', ['derp']);
confirmDetectsRenderables('{{partial "foo"}}', ['partial', 'foo']);
// error tolerance
confirmDetectsRenderables('<div>', []);
});
});