showdown.js 2.4 KB

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