Skip to content

Commit

Permalink
A few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nebrelbug committed Sep 1, 2020
1 parent 59877a7 commit 3219e0a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/deno/config.spec.ts
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
})
39 changes: 39 additions & 0 deletions test/deno/helpers.spec.ts
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"'
)
})

0 comments on commit 3219e0a

Please sign in to comment.