mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
fac62cd698
no-issue The handlebars template module is required by the proxy service, as part of the definition of the proxy service's module.exports. By destructuring the i18n property from the proxy service at the time the template module is loaded, the i18n property was always undefined, as the module.exports of the proxy service had not been set. Bypassing the proxy, and requiring the i18n module directly eliminates the circular dependency. * Refactored handlebars template tests to use proxy Since this module is intended to be used via the proxy, we should test it in the same way. We have uncovered a circular dependency issue, which would not be possible to catch in tests unless the tests were to go via the proxy. * Added breaking test for handlebars template function This test highlights the issue caused by a circular dependency, we are unable to throw an IncorrectUsageError because i18n is undefined.
21 lines
739 B
JavaScript
21 lines
739 B
JavaScript
const should = require('should');
|
|
const errors = require('@tryghost/errors');
|
|
const proxy = require('../../../../../core/frontend/services/proxy');
|
|
|
|
describe('Helpers Template', function () {
|
|
it('can execute a template', function () {
|
|
proxy.hbs.registerPartial('test', '<h1>Hello {{name}}</h1>');
|
|
|
|
const safeString = proxy.templates.execute('test', {name: 'world'});
|
|
|
|
should.exist(safeString);
|
|
safeString.should.have.property('string').and.equal('<h1>Hello world</h1>');
|
|
});
|
|
|
|
it('will throw an IncorrectUsageError if the partial does not exist', function () {
|
|
should.throws(() => {
|
|
proxy.templates.execute('non-existent');
|
|
}, errors.IncorrectUsageError);
|
|
});
|
|
});
|