From 4463975acebd923cd2f3596cf0403a3d79104ca4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 3 Jan 2016 12:29:56 -0600 Subject: [PATCH] Add `_.templateSettings.imports._.templateSettings` tests. --- test/test.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/test.js b/test/test.js index 0a8af24bf..3715171d9 100644 --- a/test/test.js +++ b/test/test.js @@ -19301,6 +19301,42 @@ assert.strictEqual(actual, '1b012'); }); + QUnit.test('should use `_.templateSettings.imports._.templateSettings`', function(assert) { + assert.expect(1); + + var lodash = _.templateSettings.imports._, + settingsClone = lodashStable.clone(lodash.templateSettings); + + lodash.templateSettings = lodashStable.assign(lodash.templateSettings, { + 'interpolate': /\{\{=([\s\S]+?)\}\}/g + }); + + var compiled = _.template('{{= a }}'); + assert.strictEqual(compiled({ 'a': 1 }), '1'); + + if (settingsClone) { + lodashStable.assign(lodash.templateSettings, settingsClone); + } else { + delete lodash.templateSettings; + } + }); + + QUnit.test('should fallback to `_.templateSettings`', function(assert) { + assert.expect(1); + + var lodash = _.templateSettings.imports._, + delimiter = _.templateSettings.interpolate; + + _.templateSettings.imports._ = { 'escape': lodashStable.escape }; + _.templateSettings.interpolate = /\{\{=([\s\S]+?)\}\}/g; + + var compiled = _.template('{{= a }}'); + assert.strictEqual(compiled({ 'a': 1 }), '1'); + + _.templateSettings.imports._ = lodash; + _.templateSettings.interpolate = delimiter; + }); + QUnit.test('should work with `this` references', function(assert) { assert.expect(2);