showdown.js 2.6 KB

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