UNPKG

shaman-website-compiler

Version:

Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.

58 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("mocha"); var sinon = require("sinon"); var _handlebars = require("handlebars"); var _fsx = require("fs-extra"); var chai_1 = require("chai"); var app_composition_1 = require("../composition/app.composition"); var models_1 = require("../models"); var handlebars_service_1 = require("./handlebars.service"); describe('GlobService', function () { var sandbox; beforeEach(function () { app_composition_1.IoC.snapshot(); sandbox = sinon.createSandbox(); app_composition_1.IoC.bind(app_composition_1.TYPES.WebsiteConfig).toConstantValue(new models_1.WebsiteConfig()); }); afterEach(function () { app_composition_1.IoC.restore(); sandbox.restore(); }); it('should be created', function () { var subject = new handlebars_service_1.HandlebarsService(); (0, chai_1.expect)(subject).not.to.be.null; }); it('registerPartials should call handlebars.registerPartial', function () { var subject = new handlebars_service_1.HandlebarsService(); var stub = sandbox.stub(_handlebars, 'registerPartial'); subject.registerPartials([new models_1.FileData("a.partial.html", "./a.partial.html")]); (0, chai_1.expect)(stub.called).to.be.true; }); it('registerHelpers should run helper files as functions', function () { var subject = new handlebars_service_1.HandlebarsService(); var content = 'handlebars.registerHelper();console.warn("test");'; var stub = sandbox.stub(_handlebars, 'registerHelper'); sandbox.stub(_fsx, 'readFile').returns(Promise.resolve(content)); subject.registerHelpers([new models_1.FileData("a.helper.js", "./a.helper.js")]); // should not have '.not.' in expect, this should be revisited (0, chai_1.expect)(stub.called).not.to.be.true; }); it('renderTemplate should use model to render if model provided', function () { var subject = new handlebars_service_1.HandlebarsService(); var file = new models_1.FileData("a.html", "./a.html"); file.content = '<div>{{model.title}}</div>'; file.model = { title: 'file.model' }; var result = subject.renderTemplate(file, { title: 'model' }); (0, chai_1.expect)(result).to.equal('<div>model</div>'); }); it('renderTemplate should use file.model to render', function () { var subject = new handlebars_service_1.HandlebarsService(); var file = new models_1.FileData("a.html", "./a.html"); file.content = '<div>{{model.title}}</div>'; file.model = { title: 'file.model' }; var result = subject.renderTemplate(file); (0, chai_1.expect)(result).to.equal('<div>file.model</div>'); }); }); //# sourceMappingURL=handlebars.service.spec.js.map