Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

68 linhas
2.3KB

  1. require('./helper');
  2. var renderHelper = require('./render-helper');
  3. var tests = renderHelper.getTests();
  4. describe('Mustache.render', function () {
  5. beforeEach(function () {
  6. Mustache.clearCache();
  7. });
  8. it('requires template to be a string', function () {
  9. assert.throws(function () {
  10. Mustache.render(['dummy template'], ['foo', 'bar']);
  11. }, TypeError, 'Invalid template! Template should be a "string" but ' +
  12. '"array" was given as the first argument ' +
  13. 'for mustache#render(template, view, partials)');
  14. });
  15. it('uses tags argument instead of Mustache.tags when given', function () {
  16. var template = '<<placeholder>>bar{{placeholder}}';
  17. Mustache.tags = ['{{', '}}'];
  18. assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']), 'foobar{{placeholder}}');
  19. });
  20. it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using Mustache.tags', function () {
  21. var template = '((placeholder))bar{{placeholder}}';
  22. Mustache.tags = ['{{', '}}'];
  23. Mustache.render(template, { placeholder: 'foo' });
  24. assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['((', '))']), 'foobar{{placeholder}}');
  25. });
  26. it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using different tags', function () {
  27. var template = '[[placeholder]]bar<<placeholder>>';
  28. Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']);
  29. assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<<placeholder>>');
  30. });
  31. it('does not mutate Mustache.tags when given tags argument', function() {
  32. var correctMustacheTags = ['{{', '}}'];
  33. Mustache.tags = correctMustacheTags;
  34. Mustache.render('((placeholder))', { placeholder: 'foo' }, {}, ['((', '))']);
  35. assert.equal(Mustache.tags, correctMustacheTags);
  36. assert.deepEqual(Mustache.tags, ['{{', '}}']);
  37. });
  38. tests.forEach(function (test) {
  39. var view = eval(test.view);
  40. it('knows how to render ' + test.name, function () {
  41. var output;
  42. if (test.partial) {
  43. output = Mustache.render(test.template, view, { partial: test.partial });
  44. } else {
  45. output = Mustache.render(test.template, view);
  46. }
  47. output.should.equal(test.expect);
  48. });
  49. });
  50. });