Last active
August 29, 2015 14:17
-
-
Save vinnymac/13e50f6464199f63e230 to your computer and use it in GitHub Desktop.
Example of testing children that use react router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React = require "react/addons" | |
{ | |
TestUtils | |
} = React.addons | |
Users = require "../Users.coffee" | |
stubRouterContext = require "utils/stubRouterContext" | |
FactoryGirl = require "factory_girl" | |
FactoryGirl.define "users", -> | |
@id = Math.random() * 101 | 0 | |
@first_name = "John" | |
@last_name = "Smith" | |
users = FactoryGirl.createLists "users", 10 | |
describe "List", -> | |
before "render and setup", -> | |
StubbedList = stubRouterContext(Users, {users: users}, {getCurrentQuery: -> {}}) | |
@list = TestUtils.renderIntoDocument(<StubbedList />) | |
# not really trying to test anything yet, just trying to render | |
it "rendered the list", -> | |
expect(@list).to.be.defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = require "underscore" | |
React = require "react" | |
classNames = require "classnames" | |
{ | |
Navigation | |
State | |
} = require "react-router" | |
User = React.createClass | |
displayName: "User" | |
mixins: [ | |
Navigation | |
State | |
] | |
render: -> | |
user = @props.model | |
<div | |
className={classNames( | |
"user" : true | |
"profile-visible" : parseInt(@getQuery().user) is user.id | |
)} | |
onClick={@handleClick} | |
> | |
{user.name} | |
</div> | |
handleClick: (e) -> | |
@transitionTo @getPathname(), {}, { | |
user : @props.model.id | |
} | |
module.exports = React.createClass | |
displayName: "UserList" | |
render: -> | |
<div id="users"> | |
{@renderUsers()} | |
</div> | |
renderUsers: -> | |
if @props.users?.length > 0 | |
_(@props.users).map (user) -> | |
<User model={user} key={user.id} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment