From 92c8f101e4873e2e6d233fb21cca1853ac48ece9 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sun, 15 Jun 2014 13:57:30 -0700 Subject: [PATCH] streamline tests --- test/specs/jsdoc/util/markdown.js | 37 ++++++------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/test/specs/jsdoc/util/markdown.js b/test/specs/jsdoc/util/markdown.js index b15349d8..488065fa 100644 --- a/test/specs/jsdoc/util/markdown.js +++ b/test/specs/jsdoc/util/markdown.js @@ -1,4 +1,4 @@ -/*global describe, env, expect, it, spyOn */ +/*global afterEach, describe, env, expect, it, spyOn */ 'use strict'; describe('jsdoc/util/markdown', function() { @@ -15,31 +15,15 @@ describe('jsdoc/util/markdown', function() { }); describe('getParser', function() { - // couple of convenience functions letting me set conf variables and restore - // them back to the originals later. + var originalMarkdownConf = env.conf.markdown; + function setMarkdownConf(hash) { - if (!env.conf.markdown) { - env.conf.markdown = {}; - } - var keys = Object.keys(hash); - var storage = {}; - for (var i = 0; i < keys.length; ++i) { - storage[keys[i]] = env.conf.markdown[keys[i]]; - // works because hash[key] is a scalar not an array/object - env.conf.markdown[keys[i]] = hash[keys[i]]; - } - return storage; + env.conf.markdown = hash; } - function restoreMarkdownConf(storage) { - var keys = Object.keys(storage); - for (var i = 0; i < keys.length; ++i) { - env.conf.markdown[keys[i]] = storage[keys[i]]; - } - if (keys.length === 0) { - delete env.conf.markdown; - } - } + afterEach(function() { + env.conf.markdown = originalMarkdownConf; + }); it('should retrieve a function when called with default settings', function() { var storage = setMarkdownConf({}); @@ -50,29 +34,24 @@ describe('jsdoc/util/markdown', function() { setMarkdownConf({parser: 'marked'}); parser = markdown.getParser(); expect(typeof parser).toEqual('function'); - - restoreMarkdownConf(storage); }); it('should use the marked parser when evilstreak is requested', function() { var storage = setMarkdownConf({parser: 'evilstreak'}); var parser = markdown.getParser(); expect(parser._parser).toEqual('marked'); - restoreMarkdownConf(storage); }); it('should use the marked parser when requested', function() { var storage = setMarkdownConf({parser: 'marked'}); var parser = markdown.getParser(); expect(parser._parser).toEqual('marked'); - restoreMarkdownConf(storage); }); it('should use the marked parser when GFM is requested', function() { var storage = setMarkdownConf({parser: 'gfm'}); var parser = markdown.getParser(); expect(parser._parser).toEqual('marked'); - restoreMarkdownConf(storage); }); it('should not apply formatting to inline tags when the marked parser is enabled', function() { @@ -82,7 +61,6 @@ describe('jsdoc/util/markdown', function() { // get the marked parser and do the test expect(parser('{@link MyClass#_x} and {@link MyClass#_y}')).toEqual( '

{@link MyClass#_x} and {@link MyClass#_y}

'); - restoreMarkdownConf(storage); }); it('should not automatically convert HTTP/HTTPS URLs to links', function() { @@ -102,7 +80,6 @@ describe('jsdoc/util/markdown', function() { spyOn(logger, 'error'); parser = markdown.getParser(); - restoreMarkdownConf(storage); expect(logger.error).toHaveBeenCalled(); });