Skip to content

Instantly share code, notes, and snippets.

@vinnymac
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinnymac/13e50f6464199f63e230 to your computer and use it in GitHub Desktop.
Save vinnymac/13e50f6464199f63e230 to your computer and use it in GitHub Desktop.
Example of testing children that use react router
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
_ = 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