smarthbs/test/test.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

import { expect, tap } from '@pushrocks/tapbundle';
import * as smarthbs from '../ts/index';
import * as path from 'path';
2017-02-19 03:12:17 +00:00
let testHbsDir = path.join(__dirname, 'hbs_testfiles');
let testPartialDir = path.join(testHbsDir, 'partials');
let testResultDir = path.join(__dirname, 'testresult');
2017-05-10 14:55:25 +00:00
2017-05-01 14:57:53 +00:00
tap.test('smarthbs -> should create partials', async () => {
await smarthbs.registerPartialDir(testPartialDir);
});
2017-02-19 03:12:17 +00:00
2017-05-01 14:57:53 +00:00
tap.test('smarthbs -> should compile a directory', async () => {
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
});
2017-02-19 03:12:17 +00:00
2017-05-01 14:57:53 +00:00
tap.test('', async () => {
let templateString = '{{{firstVar}}} {{secondVar}}';
let templateVars = await smarthbs.findVarsInHbsString(templateString);
expect(templateVars).to.include('firstVar');
expect(templateVars).to.include('secondVar');
});
2017-05-01 14:57:53 +00:00
tap.test('', async () => {
let templateString =
'{{{firstVar}}} {{secondVar}} {{thirdVar}} {{fourthVar}} {{fourthVar.someKey}} {{fourthVar.otherKey.nextKey}}';
2017-05-01 14:57:53 +00:00
let missingVars = await smarthbs.checkVarsSatisfaction(templateString, {
firstVar: 'hi',
secondVar: 'hello',
fourthVar: {
otherKey: {
nextKey: 'wow'
}
}
});
expect(missingVars).to.contain('thirdVar', 'fourthVar.someKey');
expect(missingVars).to.not.contain('secondVar', 'fourthVar.otherKey.nextKey');
});
2017-05-01 14:57:53 +00:00
tap.start();