|
| 1 | +/* |
| 2 | + * Copyright (c) 2015, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +/*global jest, describe, beforeEach, it, expect*/ |
| 12 | + |
| 13 | +jest.autoMockOff(); |
| 14 | + |
| 15 | +describe('componentMethodsHandler', () => { |
| 16 | + let documentation; |
| 17 | + let componentMethodsJsDocHandler; |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + documentation = new (require('../../Documentation')); |
| 21 | + componentMethodsJsDocHandler = require('../componentMethodsJsDocHandler'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('stays the same when no docblock is present', () => { |
| 25 | + const methods = [{ |
| 26 | + name: 'foo', |
| 27 | + docblock: null, |
| 28 | + modifiers: [], |
| 29 | + returns: null, |
| 30 | + params: [{ |
| 31 | + name: 'test', |
| 32 | + type: null, |
| 33 | + }], |
| 34 | + }]; |
| 35 | + documentation.set('methods', methods); |
| 36 | + componentMethodsJsDocHandler(documentation, null); |
| 37 | + expect(documentation.get('methods')).toEqual(methods); |
| 38 | + }); |
| 39 | + |
| 40 | + it('adds js doc types when no flow types', () => { |
| 41 | + documentation.set('methods', [{ |
| 42 | + name: 'foo', |
| 43 | + docblock: ` |
| 44 | + @param {string} test |
| 45 | + @returns {string} |
| 46 | + `, |
| 47 | + modifiers: [], |
| 48 | + returns: null, |
| 49 | + params: [{ |
| 50 | + name: 'test', |
| 51 | + type: null, |
| 52 | + }], |
| 53 | + }]); |
| 54 | + componentMethodsJsDocHandler(documentation, null); |
| 55 | + expect(documentation.get('methods')).toEqual([{ |
| 56 | + name: 'foo', |
| 57 | + description: null, |
| 58 | + docblock: ` |
| 59 | + @param {string} test |
| 60 | + @returns {string} |
| 61 | + `, |
| 62 | + modifiers: [], |
| 63 | + returns: { |
| 64 | + type: {name: 'string'}, |
| 65 | + description: null, |
| 66 | + }, |
| 67 | + params: [{ |
| 68 | + name: 'test', |
| 69 | + description: null, |
| 70 | + type: {name: 'string'}, |
| 71 | + }], |
| 72 | + }]); |
| 73 | + }); |
| 74 | + |
| 75 | + it('keeps flow types over js doc types', () => { |
| 76 | + documentation.set('methods', [{ |
| 77 | + name: 'foo', |
| 78 | + docblock: ` |
| 79 | + @param {string} test |
| 80 | + @returns {string} |
| 81 | + `, |
| 82 | + modifiers: [], |
| 83 | + returns: { |
| 84 | + type: {name: 'number'}, |
| 85 | + }, |
| 86 | + params: [{ |
| 87 | + name: 'test', |
| 88 | + type: {name: 'number'}, |
| 89 | + }], |
| 90 | + }]); |
| 91 | + componentMethodsJsDocHandler(documentation, null); |
| 92 | + expect(documentation.get('methods')).toEqual([{ |
| 93 | + name: 'foo', |
| 94 | + description: null, |
| 95 | + docblock: ` |
| 96 | + @param {string} test |
| 97 | + @returns {string} |
| 98 | + `, |
| 99 | + modifiers: [], |
| 100 | + returns: { |
| 101 | + type: {name: 'number'}, |
| 102 | + description: null, |
| 103 | + }, |
| 104 | + params: [{ |
| 105 | + name: 'test', |
| 106 | + description: null, |
| 107 | + type: {name: 'number'}, |
| 108 | + }], |
| 109 | + }]); |
| 110 | + }); |
| 111 | + |
| 112 | + it('adds descriptions', () => { |
| 113 | + documentation.set('methods', [{ |
| 114 | + name: 'foo', |
| 115 | + docblock: ` |
| 116 | + The foo method. |
| 117 | + @param test The test |
| 118 | + @returns The number |
| 119 | + `, |
| 120 | + modifiers: [], |
| 121 | + returns: null, |
| 122 | + params: [{ |
| 123 | + name: 'test', |
| 124 | + type: null, |
| 125 | + }], |
| 126 | + }]); |
| 127 | + componentMethodsJsDocHandler(documentation, null); |
| 128 | + expect(documentation.get('methods')).toEqual([{ |
| 129 | + name: 'foo', |
| 130 | + description: 'The foo method.', |
| 131 | + docblock: ` |
| 132 | + The foo method. |
| 133 | + @param test The test |
| 134 | + @returns The number |
| 135 | + `, |
| 136 | + modifiers: [], |
| 137 | + returns: { |
| 138 | + description: 'The number', |
| 139 | + type: null, |
| 140 | + }, |
| 141 | + params: [{ |
| 142 | + name: 'test', |
| 143 | + description: 'The test', |
| 144 | + type: null, |
| 145 | + }], |
| 146 | + }]); |
| 147 | + }); |
| 148 | +}); |
0 commit comments