const assert = require('assert')
const Stencil = require('../stencil')
describe('stencil test suite', () => {
it('should render nodes with the same name correctly', () => {
let actual = Stencil.render(
'{{#test}}{{#test}}{{test}}{{/test}}{{/test}}',
{
test: {
test: {
test: 'Hello World',
},
},
},
)
let expected = `Hello World`
assert.equal(actual, expected)
actual = Stencil.render(
'{{#test}}{{#test}}{{test.test}}{{/test}}{{/test}}',
{
test: {
test: {
test: {
test: 'Hello World',
},
},
},
},
)
assert.equal(actual, expected)
actual = Stencil.render(
'{{#test}}Test {{#test}}{{test.test}}{{/test}}{{/test}}',
{
test: {
test: {
test: {
test: 'Hello World',
},
},
},
},
)
expected = `Test Hello World`
assert.equal(actual, expected)
actual = Stencil.render(
'{{#test}}Test {{#test}}{{test.test}}{{/test}}{{/test}}{{#rest}}{{best}}{{/rest}}',
{
test: {
test: {
test: {
test: 'Hello World',
},
},
},
rest: {
best: ' - Best',
},
},
)
expected = `Test Hello World - Best`
assert.equal(actual, expected)
})
it('should render a simple template', () => {
const actual = Stencil.render(
'My name is {{firstName}} {{lastName}}!',
{ firstName: 'John', lastName: 'Doe' },
)
const expected = `My name is John Doe!`
assert.equal(actual, expected)
})
it('should render a view function', () => {
const view = {
firstName: 'John',
lastName: 'Doe',
fullName: function() {
return `${this.firstName} ${this.lastName}`
},
}
const actual = Stencil.render('My name is {{fullName}}!', view)
const expected = `My name is John Doe!`
assert.equal(actual, expected)
})
it('should render a view function with param', () => {
const view = {
firstName: 'John',
lastName: 'Doe',
fullName: function(firstName: string) {
return `${firstName} ${this.lastName}`
},
}
const actual = Stencil.render('My name is {{fullName Bob}}!', view)
const expected = `My name is Bob Doe!`
assert.equal(actual, expected)
})
it('should render a sub template within a variable', () => {
const view = {
logoText: `Logo`,
}
const templates = {
header: '