defaultparams.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. describe('default parameters', function() {
  3. var docSet = jasmine.getDocSetFromFile('test/fixtures/defaultparams.js');
  4. var setActive = docSet.getByLongname('setActive')[0];
  5. var setBirthYear = docSet.getByLongname('setBirthYear')[0];
  6. var setDogName = docSet.getByLongname('setDogName')[0];
  7. var setFirstName = docSet.getByLongname('setFirstName')[0];
  8. var setIsNinja = docSet.getByLongname('setIsNinja')[0];
  9. var setLastName = docSet.getByLongname('setLastName')[0];
  10. var setName = docSet.getByLongname('setName')[0];
  11. var setPizzaToppings = docSet.getByLongname('setPizzaToppings')[0];
  12. it('should automatically add string-literal values as defaults when no default value is documented', function() {
  13. expect(setFirstName.params[0].defaultvalue).toBe('Buster');
  14. });
  15. it('should not automatically mark parameters with default values as optional', function() {
  16. expect(setFirstName.params[0].optional).toBeUndefined();
  17. });
  18. it('should not automatically mark parameters with default values as nullable', function() {
  19. expect(setFirstName.params[0].nullable).toBeUndefined();
  20. });
  21. it('should not override documented default values', function() {
  22. expect(setLastName.params[0].defaultvalue).toBe('Braun');
  23. });
  24. it('should work when some parameters have default values and others do not', function() {
  25. expect(setName.params[0].defaultvalue).toBeUndefined();
  26. expect(setName.params[1].defaultvalue).toBe('Bluster');
  27. expect(setName.params[2].defaultvalue).toBe('Brown');
  28. });
  29. it('should ignore empty strings', function() {
  30. expect(setDogName.params[0].defaultvalue).toBeUndefined();
  31. });
  32. it('should work with boolean literals', function() {
  33. expect(setActive.params[0].defaultvalue).toBe(true);
  34. });
  35. it('should work with numeric literals', function() {
  36. expect(setBirthYear.params[0].defaultvalue).toBe(3000);
  37. });
  38. it('should ignore non-literal default values, such as variable identifiers', function() {
  39. expect(setPizzaToppings.params[0].defaultvalue).toBeUndefined();
  40. });
  41. it('should work when the function is assigned to a variable', function() {
  42. expect(setIsNinja.params[0].defaultvalue).toBe(true);
  43. });
  44. describe('ES2015 methods', function() {
  45. var docSet2 = jasmine.getDocSetFromFile('test/fixtures/defaultparams2.js');
  46. var setSardines = docSet2.getByLongname('PizzaToppings#setSardines')[0];
  47. it('should autodetect default parameters', function() {
  48. expect(setSardines.params[0].defaultvalue).toBe(true);
  49. });
  50. });
  51. });