showdown.js 2.2 KB

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