From 0965910fa5cfea2665fe3857e56bd2c658109629 Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Sun, 27 Jun 2010 22:09:58 +0100 Subject: [PATCH] Added tets for jsdoc.doclet. --- test/runall.js | 1 + test/tests/03_jsdoc_parser.js | 5 --- test/tests/05_jsdoc_doclet.js | 82 +++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 test/tests/05_jsdoc_doclet.js diff --git a/test/runall.js b/test/runall.js index 952bd0a2..2b5177fd 100644 --- a/test/runall.js +++ b/test/runall.js @@ -2,6 +2,7 @@ load(BASEDIR + '/test/tests/01_jsdoc_opts.js'); load(BASEDIR + '/test/tests/02_jsdoc_src.js'); load(BASEDIR + '/test/tests/03_jsdoc_parser.js'); load(BASEDIR + '/test/tests/04_jsdoc_docset.js'); +load(BASEDIR + '/test/tests/05_jsdoc_doclet.js'); // see http://visionmedia.github.com/jspec/ JSpec.run({ diff --git a/test/tests/03_jsdoc_parser.js b/test/tests/03_jsdoc_parser.js index 1201f966..10c03df2 100644 --- a/test/tests/03_jsdoc_parser.js +++ b/test/tests/03_jsdoc_parser.js @@ -28,11 +28,6 @@ expect(jsdoc.parser.result).to(be_an, Array); expect(jsdoc.parser.result).to(have_length, 1); }); - - it('should be populated by doclets', function() { - jsdoc.parser.parseFiles(BASEDIR + 'test/tests/03_jsdoc_parser.js'); - expect(jsdoc.parser.result[0].constructor.name).to(eql, 'Doclet'); - }); }); }); })(); diff --git a/test/tests/05_jsdoc_doclet.js b/test/tests/05_jsdoc_doclet.js new file mode 100644 index 00000000..1e5bde38 --- /dev/null +++ b/test/tests/05_jsdoc_doclet.js @@ -0,0 +1,82 @@ +(function() { + var jsdoc, + doclet; + + JSpec.describe('jsdoc/doclet.js', function() { + + before_each(function() { + // docsets can only be created by parsers + jsdoc = { parser: require('jsdoc/parser') }; + jsdoc.parser.parseFiles(BASEDIR + 'test/tests/05_jsdoc_doclet.js'); + doclet = jsdoc.parser.result[0]; + }); + + describe('The doclet object', function() { + it('should be a doclet', function() { + expect(doclet.constructor.name).to(eql, 'Doclet'); + }); + + it('should have a `tagText` method', function() { + expect(doclet).to(respond_to, 'toObject'); + }); + + it('should have a `hasTag` method', function() { + expect(doclet).to(respond_to, 'toObject'); + }); + + it('should have a `meta` property which is an object', function() { + expect(doclet).to(have_property, 'meta'); + expect(doclet.meta).to(be_an, Object); + }); + }); + + describe('The returned value of jsdoc.Doclet#tagText', function() { + it('should be a string', function() { + var returnedValue = doclet.tagText('name'); + expect(returnedValue).to(be_a, String); + }); + + it('should be the text of the tag that matches the given tag name', function() { + var returnedValue = doclet.tagText('name'); + expect(returnedValue).to(eql, 'Foo'); + }); + + it('should be the text of the last tag that matches the given tag name if there are more than 1', function() { + var returnedValue = doclet.tagText('param'); + expect(returnedValue).to(eql, 'b'); + }); + }); + + describe('The jsdoc.Doclet#hasTag method', function() { + it('should return a boolean', function() { + var returnedValue = doclet.hasTag('name'); + expect(returnedValue).to(be_a, Boolean); + }); + + it('should return true if the tag exists', function() { + var returnedValue = doclet.hasTag('param'); + expect(returnedValue).to(eql, true); + }); + + it('should return true even if the tag was generated by JSDoc', function() { + var returnedValue = doclet.hasTag('name'); + expect(returnedValue).to(eql, true); + }); + + it('should return false if the tag does not exist', function() { + var returnedValue = doclet.hasTag('unicorns'); + expect(returnedValue).to(eql, false); + }); + }); + }); +})(); + +(function testarea() { + + /** + @constructor Foo + @param a + @param b + */ + +})(); \ No newline at end of file