1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
# frozen_string_literal: true
require 'minitest/autorun'
require 'sprockets/cache'
require 'sprockets/jst_processor'
class TestJstProcessor < Minitest::Test
def test_export_js_template_in_JST
input = {
name: 'users/show',
content_type: 'application/javascript',
data: "function(obj) {\n return 'Hello, '+obj.name;\n}",
cache: Sprockets::Cache.new
}
output = <<-EOS
(function() { this.JST || (this.JST = {}); this.JST["users/show"] = function(obj) {
return 'Hello, '+obj.name;
};
}).call(this);
EOS
assert_equal output, Sprockets::JstProcessor.call(input)
end
def test_export_js_template_in_TEMPLATES
input = {
name: 'users/show',
content_type: 'application/javascript',
data: "function(obj) {\n return 'Hello, '+obj.name;\n}",
cache: Sprockets::Cache.new
}
output = <<-EOS
(function() { this.TEMPLATES || (this.TEMPLATES = {}); this.TEMPLATES["users/show"] = function(obj) {
return 'Hello, '+obj.name;
};
}).call(this);
EOS
assert_equal output, Sprockets::JstProcessor.new(namespace: 'this.TEMPLATES').call(input)
end
end
|