diff --git a/test/05-custom_elements.js b/test/05-custom_elements.js index de4b9ed4..b16489e9 100644 --- a/test/05-custom_elements.js +++ b/test/05-custom_elements.js @@ -833,6 +833,34 @@ describe('CustomElement', function() { }); }); + describe('#prepareRenderVariables()', () => { + it('should be called before rendering the template', (done) => { + + let code = ` + + `; + + var compiled = hawkejs.compile('template_test_with_prepared_variables', code); + + hawkejs.render(compiled, {}, function rendered(err, res) { + + if (err) { + throw err; + } + + res = res.trim(); + + try { + assertEqualHtml(res, '
1 2 3
'); + } catch (err) { + return done(err); + } + done(); + }); + + }); + }); + describe('#rendered()', () => { it('should call back when the element has been rendered', (done) => { diff --git a/test/helpers/_load.js b/test/helpers/_load.js index c2d7e3cc..1a6ad1d4 100644 --- a/test/helpers/_load.js +++ b/test/helpers/_load.js @@ -17,4 +17,5 @@ module.exports = function loadHawkejs(hawkejs) { hawkejs.load(test_base + '/helpers/nested_template_elements.js'); hawkejs.load(test_base + '/helpers/render_looper.js'); hawkejs.load(test_base + '/helpers/print_attribute.js'); + hawkejs.load(test_base + '/helpers/with_prepared_variables.js'); } \ No newline at end of file diff --git a/test/helpers/with_prepared_variables.js b/test/helpers/with_prepared_variables.js new file mode 100644 index 00000000..73a5946c --- /dev/null +++ b/test/helpers/with_prepared_variables.js @@ -0,0 +1,15 @@ +const WithPreparedVariables = Fn.inherits('Hawkejs.Element', 'WithPreparedVariables'); + +WithPreparedVariables.setTemplateFile('elements/with_prepared_variables'); +WithPreparedVariables.setAttribute('date'); + +WithPreparedVariables.setMethod(async function prepareRenderVariables() { + + await Blast.Classes.Pledge.after(5); + + let result = [1, 2, 3]; + + return { + numbers: result + }; +}); \ No newline at end of file diff --git a/test/templates/elements/with_prepared_variables.hwk b/test/templates/elements/with_prepared_variables.hwk new file mode 100644 index 00000000..1a34376e --- /dev/null +++ b/test/templates/elements/with_prepared_variables.hwk @@ -0,0 +1,9 @@ + + + + {% each numbers as nr %} + + {% /each %} + + +
{{ nr }}
\ No newline at end of file