-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts' | ||
import * as eta from '../../deno_dist/mod.ts' | ||
|
||
Deno.test('Renders a simple template with default env', () => { | ||
var res = eta.render('hi <%= it.name %>', { name: 'Ben' }, eta.defaultConfig) | ||
|
||
assertEquals(res, 'hi Ben') | ||
}) | ||
|
||
Deno.test('Renders a simple template with custom tags', () => { | ||
var res = eta.render('hi <<= it.name >>', { name: 'Ben' }, { tags: ['<<', '>>'] }) | ||
|
||
assertEquals(res, 'hi Ben') | ||
}) | ||
|
||
Deno.test('Renders a simple template without autoescaping', () => { | ||
var res = eta.render('<%= it.html %>', { html: '<p>Hi</p>' }, { autoEscape: false }) | ||
|
||
assertEquals(res, '<p>Hi</p>') // not escaped | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { assertEquals, assertThrows } from 'https://deno.land/[email protected]/testing/asserts.ts' | ||
import { render } from '../../deno_dist/mod.ts' | ||
|
||
// SHOULD TEST COMMON ETA USAGE PATTERNS HERE | ||
|
||
var eachTemplate = ` | ||
The Daugherty's have 5 kids: | ||
<ul> | ||
<% it.kids.forEach(function(kid){ %> | ||
<li><%= kid %></li> | ||
<% }) %> | ||
</ul>` | ||
|
||
Deno.test('Loop over an array', () => { | ||
var res = render(eachTemplate, { kids: ['Ben', 'Polly', 'Joel', 'Phronsie', 'Davie'] }) | ||
|
||
assertEquals( | ||
res, | ||
` | ||
The Daugherty's have 5 kids: | ||
<ul> | ||
<li>Ben</li> | ||
<li>Polly</li> | ||
<li>Joel</li> | ||
<li>Phronsie</li> | ||
<li>Davie</li> | ||
</ul>` | ||
) | ||
}) | ||
|
||
Deno.test('throws if helper "include" cannot find template', () => { | ||
assertThrows( | ||
() => { | ||
render('<%~ E.include("missing-template", it) %>', {}) | ||
}, | ||
Error, | ||
'Could not fetch template "missing-template"' | ||
) | ||
}) |