-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stateless Components #28
Changes from all commits
fade574
46fe2e7
f1ff543
90fd1ef
2b944a3
fdabdfd
e4c867c
421506e
a0e3623
0a55372
5cf5c17
6698e23
336890a
65373f5
2d821cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,4 +149,60 @@ describe('findAllComponentDefinitions', () => { | |
}); | ||
}); | ||
|
||
describe('stateless components', () => { | ||
|
||
it('finds stateless components', () => { | ||
var source = ` | ||
import React from 'React'; | ||
let ComponentA = () => <div />; | ||
function ComponentB () { return React.createElement('div', null); } | ||
const ComponentC = function(props) { return <div>{props.children}</div>; }; | ||
var Obj = { | ||
component() { if (true) { return <div />; } } | ||
}; | ||
const ComponentD = function(props) { | ||
var result = <div>{props.children}</div>; | ||
return result; | ||
}; | ||
const ComponentE = function(props) { | ||
var result = () => <div>{props.children}</div>; | ||
return result(); | ||
}; | ||
const ComponentF = function(props) { | ||
var helpers = { | ||
comp() { return <div>{props.children}</div>; } | ||
}; | ||
return helpers.comp(); | ||
}; | ||
`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function for this isn’t quite recursive enough. While all of these resolve as expected, the following two cases do not resolve correctly yet:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works like a champ. |
||
|
||
var result = parse(source); | ||
expect(Array.isArray(result)).toBe(true); | ||
expect(result.length).toBe(7); | ||
}); | ||
|
||
it('finds React.createElement, independent of the var name', () => { | ||
var source = ` | ||
import AlphaBetters from 'react'; | ||
function ComponentA () { return AlphaBetters.createElement('div', null); } | ||
function ComponentB () { return 7; } | ||
`; | ||
|
||
var result = parse(source); | ||
expect(Array.isArray(result)).toBe(true); | ||
expect(result.length).toBe(1); | ||
}); | ||
|
||
it('does not process X.createClass of other modules', () => { | ||
var source = ` | ||
import R from 'FakeReact'; | ||
const ComponentA = () => R.createElement('div', null); | ||
`; | ||
|
||
var result = parse(source); | ||
expect(Array.isArray(result)).toBe(true); | ||
expect(result.length).toBe(0); | ||
}); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is my failing test case for the bag of Components. I’m not terribly worried about this right now, personally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the bag of components still fails. I’m personally okay with this for a first iteration and if folks open an issue about it then it can be tackled.