showdown.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. require('source-map-support').install();
  2. require('chai').should();
  3. var expect = require('chai').expect,
  4. showdown = require('../../dist/showdown.js');
  5. describe('showdown.options', function () {
  6. 'use strict';
  7. describe('setOption() and getOption()', function () {
  8. it('should set option foo=bar', function () {
  9. showdown.setOption('foo', 'bar');
  10. showdown.getOption('foo').should.equal('bar');
  11. showdown.resetOptions();
  12. expect(showdown.getOption('foo')).to.be.undefined();
  13. });
  14. });
  15. describe('getDefaultOptions()', function () {
  16. it('should get default options', function () {
  17. var opts = {
  18. omitExtraWLInCodeBlocks: false,
  19. prefixHeaderId: false,
  20. noHeaderId: false
  21. };
  22. expect(showdown.getDefaultOptions()).to.be.eql(opts);
  23. });
  24. });
  25. });
  26. describe('showdown.extension()', function () {
  27. 'use strict';
  28. var extObjMock = {
  29. type: 'lang',
  30. filter: function () {}
  31. },
  32. extObjFunc = function () {
  33. return extObjMock;
  34. };
  35. describe('should register', function () {
  36. it('an extension object', function () {
  37. showdown.extension('foo', extObjMock);
  38. showdown.extension('foo').should.eql([extObjMock]);
  39. showdown.resetExtensions();
  40. });
  41. it('an extension function', function () {
  42. showdown.extension('foo', extObjFunc);
  43. showdown.extension('foo').should.eql([extObjMock]);
  44. showdown.resetExtensions();
  45. });
  46. });
  47. describe('should refuse to register', function () {
  48. it('a generic object', function () {
  49. var fn = function () {
  50. showdown.extension('foo', {});
  51. };
  52. expect(fn).to.throw();
  53. });
  54. it('an extension with invalid type', function () {
  55. var fn = function () {
  56. showdown.extension('foo', {
  57. type: 'foo'
  58. });
  59. };
  60. expect(fn).to.throw(/type .+? is not recognized\. Valid values: "lang" or "output"/);
  61. });
  62. it('an extension without regex or filter', function () {
  63. var fn = function () {
  64. showdown.extension('foo', {
  65. type: 'lang'
  66. });
  67. };
  68. expect(fn).to.throw(/extensions must define either a "regex" property or a "filter" method/);
  69. });
  70. });
  71. });
  72. describe('showdown.getAllExtensions()', function () {
  73. 'use strict';
  74. var extObjMock = {
  75. type: 'lang',
  76. filter: function () {}
  77. };
  78. it('should return all extensions', function () {
  79. showdown.extension('bar', extObjMock);
  80. showdown.getAllExtensions().should.eql({bar: [extObjMock]});
  81. });
  82. });