showdown.js 2.6 KB

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