jsdoc/test/specs/documentation/defaultparams.js
Jeff Williams 878115e1c1 autodetect string, boolean, and numeric default values of parameters (#555)
We ignore other types based on these assumptions:

1) It doesn't make sense to show variable identifiers, which may refer to (for example) module-private values that should not be documented.
2) If we tried to capture objects and arrays, we would have to iterate over them to see if they contain any variable identifiers, which would be a pain (and potentially confusing: "Why do some objects appear in the docs but not others?")
3) Most developers will not define complex default values in a function definition.
4) In many cases, object and array default values will be `{}` and `[]`, respectively, and usually those don't merit documentation.
2015-03-03 17:22:30 -08:00

56 lines
2.4 KiB
JavaScript

'use strict';
// Rhino can't handle default parameters
if (jasmine.jsParser !== 'rhino') {
describe('default parameters', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/defaultparams.js');
var setActive = docSet.getByLongname('setActive')[0];
var setBirthYear = docSet.getByLongname('setBirthYear')[0];
var setDogName = docSet.getByLongname('setDogName')[0];
var setFirstName = docSet.getByLongname('setFirstName')[0];
var setLastName = docSet.getByLongname('setLastName')[0];
var setManager = docSet.getByLongname('setManager')[0];
var setName = docSet.getByLongname('setName')[0];
var setPizzaToppings = docSet.getByLongname('setPizzaToppings')[0];
it('should automatically add string-literal values as defaults when no default value is documented', function() {
expect(setFirstName.params[0].defaultvalue).toBe('Buster');
});
it('should not automatically mark parameters with default values as optional', function() {
expect(setFirstName.params[0].optional).toBeUndefined();
});
it('should not automatically mark parameters with default values as nullable', function() {
expect(setFirstName.params[0].nullable).toBeUndefined();
});
it('should not override documented default values', function() {
expect(setLastName.params[0].defaultvalue).toBe('Braun');
});
it('should work when some parameters have default values and others do not', function() {
expect(setName.params[0].defaultvalue).toBeUndefined();
expect(setName.params[1].defaultvalue).toBe('Bluster');
expect(setName.params[2].defaultvalue).toBe('Brown');
});
it('should ignore empty strings', function() {
expect(setDogName.params[0].defaultvalue).toBeUndefined();
});
it('should work with boolean literals', function() {
expect(setActive.params[0].defaultvalue).toBe(true);
});
it('should work with numeric literals', function() {
expect(setBirthYear.params[0].defaultvalue).toBe(3000);
});
it('should ignore non-literal default values, such as variable identifiers', function() {
expect(setPizzaToppings.params[0].defaultvalue).toBeUndefined();
});
});
}