reel-of-js-fortune/test/util/gin.test.ts

59 lines
No EOL
1.4 KiB
TypeScript

import { describe, it, expect, beforeAll } from 'bun:test'
import { Engine } from '../../src/util/gin'
describe('Gin template porting test', () => {
const e = new Engine();
beforeAll(async () => {
await e.LoadHTMLGlob('examples/*html');
e.printTemplates();
})
it('data', async () => {
const data = [
{
Name: 'Aunt Mildred',
Gift: 'bone china tea set',
Attended: true,
},
{
Name: 'Uncle John',
Gift: 'moleskin pants',
Attended: false,
},
{
Name: 'Cousin Rodney',
Gift: '',
Attended: false,
},
]
const expected =
`Dear Aunt Mildred,
It was a pleasure to see you at the wedding.
Thank you for the lovely bone china tea set.
Best wishes,
Josie
Dear Uncle John,
It is a shame you couldn't make it to the wedding.
Thank you for the lovely moleskin pants.
Best wishes,
Josie
Dear Cousin Rodney,
It is a shame you couldn't make it to the wedding.
Best wishes,
Josie`
const actual = data.map(d => e.HTML("examples/data.html", d)).join('\n');
expect(actual).toEqual(expected);
})
it('define', async () => {
expect(e.HTML("T1", {})).toEqual('ONE')
expect(e.HTML("T2", {})).toEqual('TWO')
expect(e.HTML("T3", {})).toEqual('ONE TWO')
})
})