diff --git a/src/js/_enqueues/wp/util.js b/src/js/_enqueues/wp/util.js index f6425f2178bcb..37a18655e2e1f 100644 --- a/src/js/_enqueues/wp/util.js +++ b/src/js/_enqueues/wp/util.js @@ -7,7 +7,7 @@ /** @namespace wp */ window.wp = window.wp || {}; -(function ($) { +(function ($, _) { // Check for the utility settings. var settings = typeof _wpUtilSettings === 'undefined' ? {} : _wpUtilSettings; @@ -154,4 +154,4 @@ window.wp = window.wp || {}; } }; -}(jQuery)); +}(jQuery, _)); diff --git a/tests/qunit/index.html b/tests/qunit/index.html index d0e81acedb502..bc2c2c43964a3 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -157,6 +157,7 @@ + diff --git a/tests/qunit/wp-includes/js/wp-util.js b/tests/qunit/wp-includes/js/wp-util.js new file mode 100644 index 0000000000000..70a04447a87f3 --- /dev/null +++ b/tests/qunit/wp-includes/js/wp-util.js @@ -0,0 +1,25 @@ +/* global wp */ + +QUnit.module( 'wp.template' ); + +QUnit.test( 'uses the Underscore instance available at initialization', function( assert ) { + var originalUnderscore = window._; + + document.getElementById( 'qunit-fixture' ).innerHTML = + ''; + + window._ = { + template: function() { + return 'not a function'; + } + }; + + try { + assert.strictEqual( + wp.template( 'wp-util-test' )( { name: 'World' } ), + 'Hello World' + ); + } finally { + window._ = originalUnderscore; + } +} );