Reset options before switching to a flavor (#365)

fix(flavors): reset options before switching to a flavor
This commit is contained in:
simo 2017-03-31 01:17:10 +03:00 committed by Estevão Soares dos Santos
parent 759a334e13
commit 3e22fc658c
2 changed files with 26 additions and 0 deletions

View File

@ -114,6 +114,7 @@ showdown.setFlavor = function (name) {
if (!flavor.hasOwnProperty(name)) {
throw Error(name + ' flavor was not found');
}
showdown.resetOptions();
var preset = flavor[name];
setFlavor = name;
for (var option in preset) {

View File

@ -130,4 +130,29 @@ describe('showdown.setFlavor()', function () {
}
showdown.setFlavor('vanilla');
});
it('should switch between flavors correctly', function () {
showdown.setFlavor('github');
var ghOpts = showdown.getFlavorOptions('github'),
shOpts = showdown.getOptions(),
dfOpts = showdown.getDefaultOptions();
for (var opt in dfOpts) {
if (ghOpts.hasOwnProperty(opt)) {
shOpts[opt].should.equal(ghOpts[opt]);
} else {
shOpts[opt].should.equal(dfOpts[opt]);
}
}
showdown.setFlavor('original');
var orOpts = showdown.getFlavorOptions('original');
shOpts = showdown.getOptions();
for (opt in dfOpts) {
if (orOpts.hasOwnProperty(opt)) {
shOpts[opt].should.equal(orOpts[opt]);
} else {
shOpts[opt].should.equal(dfOpts[opt]);
}
}
showdown.setFlavor('vanilla');
});
});