showdown.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. headerLevelStart: 1,
  22. parseImgDimensions: false,
  23. simplifiedAutoLink: false
  24. };
  25. expect(showdown.getDefaultOptions()).to.be.eql(opts);
  26. });
  27. });
  28. });
  29. describe('showdown.extension()', function () {
  30. 'use strict';
  31. var extObjMock = {
  32. type: 'lang',
  33. filter: function () {}
  34. },
  35. extObjFunc = function () {
  36. return extObjMock;
  37. };
  38. describe('should register', function () {
  39. it('an extension object', function () {
  40. showdown.extension('foo', extObjMock);
  41. showdown.extension('foo').should.eql([extObjMock]);
  42. showdown.resetExtensions();
  43. });
  44. it('an extension function', function () {
  45. showdown.extension('foo', extObjFunc);
  46. showdown.extension('foo').should.eql([extObjMock]);
  47. showdown.resetExtensions();
  48. });
  49. });
  50. describe('should refuse to register', function () {
  51. it('a generic object', function () {
  52. var fn = function () {
  53. showdown.extension('foo', {});
  54. };
  55. expect(fn).to.throw();
  56. });
  57. it('an extension with invalid type', function () {
  58. var fn = function () {
  59. showdown.extension('foo', {
  60. type: 'foo'
  61. });
  62. };
  63. expect(fn).to.throw(/type .+? is not recognized\. Valid values: "lang" or "output"/);
  64. });
  65. it('an extension without regex or filter', function () {
  66. var fn = function () {
  67. showdown.extension('foo', {
  68. type: 'lang'
  69. });
  70. };
  71. expect(fn).to.throw(/extensions must define either a "regex" property or a "filter" method/);
  72. });
  73. });
  74. });
  75. describe('showdown.getAllExtensions()', function () {
  76. 'use strict';
  77. var extObjMock = {
  78. type: 'lang',
  79. filter: function () {}
  80. };
  81. it('should return all extensions', function () {
  82. showdown.extension('bar', extObjMock);
  83. showdown.getAllExtensions().should.eql({bar: [extObjMock]});
  84. });
  85. });