this.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. 'use strict';
  2. describe('this', function() {
  3. describe('attaching members to "this"', function() {
  4. var docSet = jasmine.getDocSetFromFile('test/fixtures/this.js');
  5. var found1 = docSet.getByLongname('Singer#tralala');
  6. var found2 = docSet.getByLongname('Singer#isSinging');
  7. describe('in a contructor', function() {
  8. it('should have a longname like Constructor#member', function() {
  9. expect(found1.length).toBe(1);
  10. });
  11. it('should have a correct short name', function() {
  12. expect(found1[0].name).toBe('tralala');
  13. });
  14. it('should have a correct memberof', function() {
  15. expect(found1[0].memberof).toBe('Singer');
  16. });
  17. it('should default to an "instance" scope', function() {
  18. expect(found1[0].scope).toBe('instance');
  19. });
  20. });
  21. describe('in a method of a constructor', function() {
  22. it('should have a longname like Constructor#member', function() {
  23. expect(found2.length).toBe(1);
  24. });
  25. it('should have a correct short name', function() {
  26. expect(found2[0].name).toBe('isSinging');
  27. });
  28. it('should have a correct memberof', function() {
  29. expect(found2[0].memberof).toBe('Singer');
  30. });
  31. it('should default to an "instance" scope', function() {
  32. expect(found2[0].scope).toBe('instance');
  33. });
  34. });
  35. });
  36. describe('when a contructor is nested inside another constructor', function() {
  37. var docSet = jasmine.getDocSetFromFile('test/fixtures/this2.js');
  38. var found = docSet.getByLongname('TemplateBuilder#Template#rendered');
  39. it('should have a longname like Constructor#Constructor#member', function() {
  40. expect(found.length).toBe(1);
  41. });
  42. it('should have a correct short name', function() {
  43. expect(found[0].name).toBe('rendered');
  44. });
  45. it('should have a correct memberof', function() {
  46. expect(found[0].memberof).toBe('TemplateBuilder#Template');
  47. });
  48. it('should default to an "instance" scope', function() {
  49. expect(found[0].scope).toBe('instance');
  50. });
  51. });
  52. describe('When a this is assigned to inside a non-constructor function', function() {
  53. var docSet = jasmine.getDocSetFromFile('test/fixtures/this3.js');
  54. var found = docSet.getByLongname('position');
  55. it('should have a global member name like "member"', function() {
  56. expect(found.length).toBe(1);
  57. });
  58. it('should have a correct short name', function() {
  59. expect(found[0].name).toBe('position');
  60. });
  61. it('should have a correct memberof', function() {
  62. expect(found[0].memberof).toBeUndefined();
  63. });
  64. });
  65. describe('When "this" is assigned inside an explicit definition of the class constructor', function() {
  66. var docSet = jasmine.getDocSetFromFile('test/fixtures/this4.js');
  67. var found = docSet.getByLongname('Template#render');
  68. it('should have a longname like Constructor#member', function() {
  69. expect(found.length).toBe(1);
  70. });
  71. it('should have the correct name', function() {
  72. expect(found[0].name).toBe('render');
  73. });
  74. it('should have the correct memberof', function() {
  75. expect(found[0].memberof).toBe('Template');
  76. });
  77. });
  78. describe('When "this" is assigned in a chained declaration in a module', function() {
  79. var docSet = jasmine.getDocSetFromFile('test/fixtures/this5.js');
  80. var found = docSet.getByLongname('module:template.Template#view');
  81. it('should have a longname like Constructor#member', function() {
  82. expect(found.length).toBe(1);
  83. });
  84. it('should have the correct name', function() {
  85. expect(found[0].name).toBe('view');
  86. });
  87. it('should have the correct memberof', function() {
  88. expect(found[0].memberof).toBe('module:template.Template');
  89. });
  90. });
  91. describe('When `this` is within the constructor in a class that has an `@alias` tag within a module', function() {
  92. var docSet = jasmine.getDocSetFromFile('test/fixtures/this6.js');
  93. var someProperty = docSet.getByLongname('module:example#_someProperty')[0];
  94. it('should have the correct longname, name, and scope', function() {
  95. expect(someProperty).toBeDefined();
  96. expect(someProperty.name).toBe('_someProperty');
  97. expect(someProperty.scope).toBe('instance');
  98. });
  99. });
  100. describe('When a member is nested inside an objectlit "this" property inside a constructor', function() {
  101. var docSet = jasmine.getDocSetFromFile('test/fixtures/this-and-objectlit.js');
  102. var found = docSet.getByLongname('Page#parts.body.heading');
  103. it('should have a longname like Constructor#objlit.member', function() {
  104. expect(found.length).toBe(1);
  105. });
  106. it('should have a correct short name', function() {
  107. expect(found[0].name).toBe('heading');
  108. });
  109. it('should have a correct memberof', function() {
  110. expect(found[0].memberof).toBe('Page#parts.body');
  111. });
  112. it('should default to a "static" scope', function() {
  113. expect(found[0].scope).toBe('static');
  114. });
  115. });
  116. });