Skip to content

Commit c9651c0

Browse files
author
John Doherty
committed
added unit test
1 parent a561e3e commit c9651c0

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

test/data/test-instance.js

Whitespace-only changes.

test/data/test-singleton.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @schema.name product
3+
* @schema.description An e-commerce product
4+
*/
5+
var product = {
6+
7+
/**
8+
* @schema.title Name
9+
* @schema.description The SEO friendly name of the product
10+
* @schema.type string
11+
* @schema.minLength 3
12+
* @schema.maxLength 255
13+
* @schema.required true
14+
*/
15+
name: '',
16+
17+
/**
18+
* @schema.title Url
19+
* @schema.description Unique, SEO friendly product Url
20+
* @schema.type string
21+
* @schema.minLength 1
22+
* @schema.maxLength 255
23+
* @schema.required true
24+
*/
25+
url: '',
26+
27+
/**
28+
* @schema.title Price
29+
* @schema.description Price of the product
30+
* @schema.type number
31+
* @schema.minimum 0
32+
* @schema.required true
33+
*/
34+
price: ''
35+
};

test/jsdoctojsonschema.spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
11
'use strict';
22

33
var toJsonSchema = require('../index.js');
4+
var path = require('path');
45

56
describe('jsdoc-to-json-schema', function () {
67

78
it('should be defined', function () {
89
expect(toJsonSchema).toBeDefined();
910
});
11+
12+
it('should return JSON Schema for JS singleton', function (done) {
13+
14+
var inputFile = path.resolve('./test/data/test-singleton.js');
15+
16+
// generate a JSON schema for product.js
17+
toJsonSchema(inputFile).then(function(schema){
18+
19+
expect(schema).toBeDefined();
20+
21+
// top level
22+
expect(schema.name).toEqual('product');
23+
expect(schema.description).toEqual('An e-commerce product');
24+
expect(schema.properties).toBeDefined();
25+
26+
// .name property
27+
expect(schema.properties.name).toBeDefined();
28+
expect(schema.properties.name.type).toEqual('string');
29+
expect(schema.properties.name.title).toEqual('Name');
30+
expect(schema.properties.name.description).toEqual('The SEO friendly name of the product');
31+
expect(schema.properties.name.minLength).toEqual(3);
32+
expect(schema.properties.name.maxLength).toEqual(255);
33+
expect(schema.properties.name.required).toEqual(true);
34+
35+
// .url property
36+
expect(schema.properties.url).toBeDefined();
37+
expect(schema.properties.url.type).toEqual('string');
38+
expect(schema.properties.url.title).toEqual('Url');
39+
expect(schema.properties.url.description).toEqual('Unique, SEO friendly product Url');
40+
expect(schema.properties.url.minLength).toEqual(1);
41+
expect(schema.properties.url.maxLength).toEqual(255);
42+
expect(schema.properties.url.required).toEqual(true);
43+
44+
// .price property
45+
expect(schema.properties.price).toBeDefined();
46+
expect(schema.properties.price.type).toEqual('number');
47+
expect(schema.properties.price.title).toEqual('Price');
48+
expect(schema.properties.price.description).toEqual('Price of the product');
49+
expect(schema.properties.price.minimum).toEqual(0);
50+
expect(schema.properties.price.required).toEqual(true);
51+
52+
done();
53+
})
54+
.catch(function(err){
55+
done(err);
56+
});
57+
});
58+
1059
});

0 commit comments

Comments
 (0)