|
8 | 8 | *
|
9 | 9 | */
|
10 | 10 |
|
11 |
| -"use strict"; |
| 11 | +/*global jest, describe, beforeEach, it, expect*/ |
12 | 12 |
|
13 | 13 | jest.autoMockOff();
|
14 | 14 |
|
15 |
| -var source = [ |
16 |
| - 'var React = require("React");', |
17 |
| - 'var PropTypes = React.PropTypes;', |
18 |
| - '/**', |
19 |
| - ' * Example component description', |
20 |
| - ' */', |
21 |
| - 'var Component = React.createClass({', |
22 |
| - ' propTypes: {', |
23 |
| - ' /**', |
24 |
| - ' * Example prop description', |
25 |
| - ' */', |
26 |
| - ' foo: PropTypes.bool', |
27 |
| - ' },', |
28 |
| - ' getDefaultProps: function() {', |
29 |
| - ' return {', |
30 |
| - ' foo: true', |
31 |
| - ' };', |
32 |
| - ' }', |
33 |
| - '});', |
34 |
| - 'module.exports = Component;' |
35 |
| -].join('\n'); |
36 |
| - |
37 | 15 | describe('main', () => {
|
38 |
| - var utils; |
39 | 16 | var docgen;
|
40 | 17 |
|
41 | 18 | beforeEach(() => {
|
42 |
| - utils = require('../../tests/utils'); |
43 | 19 | docgen = require('../main');
|
44 | 20 | });
|
45 | 21 |
|
46 |
| - it('parses with default resolver/handlers', () => { |
47 |
| - var docs = docgen.parse(source); |
48 |
| - expect(docs).toEqual({ |
49 |
| - description: 'Example component description', |
50 |
| - props: { |
51 |
| - foo: { |
52 |
| - type: { |
53 |
| - name: 'bool' |
54 |
| - }, |
55 |
| - defaultValue: { |
56 |
| - computed: false, |
57 |
| - value: 'true' |
| 22 | + function test(source) { |
| 23 | + it('parses with default resolver/handlers', () => { |
| 24 | + var docs = docgen.parse(source); |
| 25 | + expect(docs).toEqual({ |
| 26 | + description: 'Example component description', |
| 27 | + props: { |
| 28 | + foo: { |
| 29 | + type: { |
| 30 | + name: 'bool', |
| 31 | + }, |
| 32 | + defaultValue: { |
| 33 | + computed: false, |
| 34 | + value: 'true', |
| 35 | + }, |
| 36 | + description: 'Example prop description', |
| 37 | + required: false, |
58 | 38 | },
|
59 |
| - description: 'Example prop description', |
60 |
| - required: false |
61 |
| - } |
62 |
| - } |
| 39 | + }, |
| 40 | + }); |
63 | 41 | });
|
64 |
| - }); |
65 | 42 |
|
66 |
| - it('parses with custom handlers', () => { |
67 |
| - var docs = docgen.parse(source, null, [ |
68 |
| - docgen.handlers.componentDocblockHandler, |
69 |
| - ]); |
70 |
| - expect(docs).toEqual({ |
71 |
| - description: 'Example component description', |
72 |
| - props: {} |
| 43 | + it('parses with custom handlers', () => { |
| 44 | + var docs = docgen.parse(source, null, [ |
| 45 | + docgen.handlers.componentDocblockHandler, |
| 46 | + ]); |
| 47 | + expect(docs).toEqual({ |
| 48 | + description: 'Example component description', |
| 49 | + props: {}, |
| 50 | + }); |
73 | 51 | });
|
| 52 | + } |
| 53 | + |
| 54 | + describe('React.createClass', () => { |
| 55 | + test(` |
| 56 | + var React = require("React"); |
| 57 | + var PropTypes = React.PropTypes; |
| 58 | + /** |
| 59 | + * Example component description |
| 60 | + */ |
| 61 | + var Component = React.createClass({ |
| 62 | + propTypes: { |
| 63 | + /** |
| 64 | + * Example prop description |
| 65 | + */ |
| 66 | + foo: PropTypes.bool |
| 67 | + }, |
| 68 | + getDefaultProps: function() { |
| 69 | + return { |
| 70 | + foo: true |
| 71 | + }; |
| 72 | + } |
| 73 | + }); |
| 74 | + module.exports = Component |
| 75 | + `); |
74 | 76 | });
|
| 77 | + |
| 78 | + describe('Class definition', () => { |
| 79 | + test(` |
| 80 | + var React = require("React"); |
| 81 | + var PropTypes = React.PropTypes; |
| 82 | + /** |
| 83 | + * Example component description |
| 84 | + */ |
| 85 | + export default class Component extends React.Component { |
| 86 | + static propTypes = { |
| 87 | + /** |
| 88 | + * Example prop description |
| 89 | + */ |
| 90 | + foo: PropTypes.bool |
| 91 | + }; |
| 92 | + // ... |
| 93 | + } |
| 94 | + Component.defaultProps = { |
| 95 | + foo: true, |
| 96 | + }; |
| 97 | + `); |
| 98 | + }); |
| 99 | + |
75 | 100 | });
|
0 commit comments