mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 21:46:07 +08:00
Update react-docgen
This commit is contained in:
75
website/react-docgen/lib/__tests__/main-test.js
vendored
Normal file
75
website/react-docgen/lib/__tests__/main-test.js
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
var source = [
|
||||
'var React = require("React");',
|
||||
'var PropTypes = React.PropTypes;',
|
||||
'/**',
|
||||
' * Example component description',
|
||||
' */',
|
||||
'var Component = React.createClass({',
|
||||
' propTypes: {',
|
||||
' /**',
|
||||
' * Example prop description',
|
||||
' */',
|
||||
' foo: PropTypes.bool',
|
||||
' },',
|
||||
' getDefaultProps: function() {',
|
||||
' return {',
|
||||
' foo: true',
|
||||
' };',
|
||||
' }',
|
||||
'});',
|
||||
'module.exports = Component;'
|
||||
].join('\n');
|
||||
|
||||
describe('main', function() {
|
||||
var utils;
|
||||
var docgen;
|
||||
|
||||
beforeEach(function() {
|
||||
utils = require('../../tests/utils');
|
||||
docgen = require('../main');
|
||||
});
|
||||
|
||||
it('parses with default resolver/handlers', function() {
|
||||
var docs = docgen.parse(source);
|
||||
expect(docs).toEqual({
|
||||
description: 'Example component description',
|
||||
props: {
|
||||
foo: {
|
||||
type: {
|
||||
name: 'bool'
|
||||
},
|
||||
defaultValue: {
|
||||
computed: false,
|
||||
value: 'true'
|
||||
},
|
||||
description: 'Example prop description',
|
||||
required: false
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('parses with custom handlers', function() {
|
||||
var docs = docgen.parse(source, null, [
|
||||
docgen.handlers.componentDocblockHandler,
|
||||
]);
|
||||
expect(docs).toEqual({
|
||||
description: 'Example component description',
|
||||
props: {}
|
||||
});
|
||||
});
|
||||
});
|
||||
52
website/react-docgen/lib/__tests__/parse-test.js
vendored
Normal file
52
website/react-docgen/lib/__tests__/parse-test.js
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
describe('parse', function() {
|
||||
var utils;
|
||||
var parse;
|
||||
|
||||
beforeEach(function() {
|
||||
utils = require('../../tests/utils');
|
||||
parse = require('../parse');
|
||||
});
|
||||
|
||||
function pathFromSource(source) {
|
||||
return utils.parse(source).get('body', 0, 'expression');
|
||||
}
|
||||
|
||||
it('allows custom component definition resolvers', function() {
|
||||
var path = pathFromSource('({foo: "bar"})');
|
||||
var resolver = jest.genMockFunction().mockReturnValue(path);
|
||||
var handler = jest.genMockFunction();
|
||||
parse('', resolver, [handler]);
|
||||
|
||||
expect(resolver).toBeCalled();
|
||||
expect(handler.mock.calls[0][1]).toBe(path);
|
||||
});
|
||||
|
||||
it('errors if component definition is not found', function() {
|
||||
var resolver = jest.genMockFunction();
|
||||
expect(function() {
|
||||
parse('', resolver);
|
||||
}).toThrow(parse.ERROR_MISSING_DEFINITION);
|
||||
expect(resolver).toBeCalled();
|
||||
|
||||
handler = jest.genMockFunction().mockReturnValue([]);
|
||||
expect(function() {
|
||||
parse('', resolver);
|
||||
}).toThrow(parse.ERROR_MISSING_DEFINITION);
|
||||
expect(resolver).toBeCalled();
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user