From 0422add48fa76f2bdd7bc7ccfd56be21430399d0 Mon Sep 17 00:00:00 2001 From: mathematicalcoffee Date: Fri, 15 Feb 2013 14:11:20 +1000 Subject: [PATCH] @example: added tests --- test/specs/tags/exampletag.js | 22 +++++++++++++++++++ test/specs/tags/exportstag.js | 40 +++++++++++++++++------------------ 2 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 test/specs/tags/exampletag.js diff --git a/test/specs/tags/exampletag.js b/test/specs/tags/exampletag.js new file mode 100644 index 00000000..01ce8214 --- /dev/null +++ b/test/specs/tags/exampletag.js @@ -0,0 +1,22 @@ +describe("@example tag", function() { + var doclet = require('jsdoc/doclet'), + txt = 'console.log("foo");\nconsole.log("bar");', + txt2 = '1 + 2;', + doc = new doclet.Doclet('/** @example\n' + txt + '*/', {}), + doc2 = new doclet.Doclet('/** @example\n' + txt + '\n@example\n' + txt2 + '*/', {}); + + it("creates an 'examples' property on the doclet with the example", function() { + expect(doc.examples).toBeDefined(); + expect(Array.isArray(doc.examples)).toBe(true); + expect(doc.examples.length).toBe(1); + expect(doc.examples).toContain(txt); + }); + + it("can be specified multiple times on one doclet", function() { + expect(doc2.examples).toBeDefined(); + expect(Array.isArray(doc2.examples)).toBe(true); + expect(doc2.examples.length).toBe(2); + expect(doc2.examples).toContain(txt); + expect(doc2.examples).toContain(txt2); + }); +}); diff --git a/test/specs/tags/exportstag.js b/test/specs/tags/exportstag.js index 9d11ad91..6d422754 100644 --- a/test/specs/tags/exportstag.js +++ b/test/specs/tags/exportstag.js @@ -8,24 +8,24 @@ describe("@exports tag", function() { size = docSet.getByLongname('module:my/shirt.Turtleneck#size')[0]; it('When an objlit symbol has an @exports tag, the doclet is aliased to "module:" + the tag value.', function() { - expect(typeof shirt).toBe('object'); - expect(shirt.alias).toBe('my/shirt'); + expect(typeof shirt).toEqual('object'); + expect(shirt.alias).toEqual('my/shirt'); }); it('When an objlit symbol has an @exports tag, the doclet\'s longname includes the "module:" namespace.', function() { - expect(shirt.longname).toBe('module:my/shirt'); + expect(shirt.longname).toEqual('module:my/shirt'); }); it('When an objlit symbol has an @exports tag, the doclet kind is set to module.', function() { - expect(shirt.kind).toBe('module'); + expect(shirt.kind).toEqual('module'); }); it('When an objlit symbol has an @exports tag, the objlit members are documented as members of the module.', function() { - expect(typeof color).toBe('object'); - expect(color.memberof).toBe('module:my/shirt'); + expect(typeof color).toEqual('object'); + expect(color.memberof).toEqual('module:my/shirt'); - expect(typeof tneck).toBe('object'); - expect(typeof size).toBe('object'); + expect(typeof tneck).toEqual('object'); + expect(typeof size).toEqual('object'); }); }); @@ -35,21 +35,21 @@ describe("@exports tag", function() { wool = docSet.getByLongname('module:my/coat#wool')[0]; it('When a function symbol has an @exports tag, the doclet is aliased to "module:" + the tag value.', function() { - expect(typeof coat).toBe('object'); - expect(coat.alias).toBe('my/coat'); + expect(typeof coat).toEqual('object'); + expect(coat.alias).toEqual('my/coat'); }); it('When a function symbol has an @exports tag, the doclet\'s longname includes the "module:" namespace.', function() { - expect(coat.longname).toBe('module:my/coat'); + expect(coat.longname).toEqual('module:my/coat'); }); it('When a function symbol has an @exports tag, the doclet kind is set to module.', function() { - expect(coat.kind).toBe('module'); + expect(coat.kind).toEqual('module'); }); it('When a function symbol has an @exports tag, the this members are documented as instance members of the module.', function() { - expect(typeof wool).toBe('object'); - expect(wool.memberof).toBe('module:my/coat'); + expect(typeof wool).toEqual('object'); + expect(wool.memberof).toEqual('module:my/coat'); }); }); @@ -60,13 +60,13 @@ describe("@exports tag", function() { inhead = docSet.getByLongname('module:html/utils.isInHead')[0]; it('When a function symbol has an @exports tag and there is an objlit named "exports" the members are documented as members of the module.', function() { - expect(typeof getstyle).toBe('object'); - expect(getstyle.memberof).toBe('module:html/utils'); + expect(typeof getstyle).toEqual('object'); + expect(getstyle.memberof).toEqual('module:html/utils'); }); it('When a function symbol has an @exports tag and there are members assinged to an "exports" name, the members are documented as members of the module.', function() { - expect(typeof inhead).toBe('object'); - expect(inhead.memberof).toBe('module:html/utils'); + expect(typeof inhead).toEqual('object'); + expect(inhead.memberof).toEqual('module:html/utils'); }); }); @@ -77,12 +77,12 @@ describe("@exports tag", function() { method = docSet.getByLongname('module:some/module~myClass#myMethod')[0]; it('An inner class declared as a function in a module should be documented.', function() { - expect(typeof innerClass).toBe('object'); + expect(typeof innerClass).toEqual('object'); //expect(getstyle.memberof, 'module:html/utils'); }); it('A method of an inner class declared as a function in a module should be documented.', function() { - expect(typeof method).toBe('object'); + expect(typeof method).toEqual('object'); //expect(inhead.memberof, 'module:html/utils'); }); });