|
1 |
| -import expect from 'expect' |
| 1 | +import expect, { spyOn, restoreSpies } from 'expect' |
2 | 2 | import React, { PropTypes } from 'react'
|
3 | 3 | import Link from '../Link'
|
4 | 4 | import { render } from 'react-dom'
|
5 | 5 | import { LocationBroadcast } from '../Broadcasts'
|
| 6 | +import * as broadcasters from '../Broadcasts' |
6 | 7 |
|
7 | 8 | describe('Link', () => {
|
8 | 9 |
|
@@ -287,4 +288,59 @@ describe('Link', () => {
|
287 | 288 | expect(a.className).toEqual('active')
|
288 | 289 | })
|
289 | 290 | })
|
| 291 | + |
| 292 | + describe('knowledge of location', () => { |
| 293 | + |
| 294 | + beforeEach(() => { |
| 295 | + spyOn(broadcasters, 'LocationSubscriber').andCallThrough() |
| 296 | + }) |
| 297 | + |
| 298 | + afterEach(() => { |
| 299 | + restoreSpies() |
| 300 | + }) |
| 301 | + |
| 302 | + it('renders <LocationSubscriber> when it has an activeClassName', () => { |
| 303 | + const div = document.createElement('div') |
| 304 | + render(( |
| 305 | + <Link |
| 306 | + to='/foo' |
| 307 | + activeClassName='active' |
| 308 | + location={{ pathname: '/bar' }} |
| 309 | + /> |
| 310 | + ), div) |
| 311 | + expect(broadcasters.LocationSubscriber).toHaveBeenCalled() |
| 312 | + }) |
| 313 | + |
| 314 | + it('renders <LocationSubscriber> when it has an activeStyle', () => { |
| 315 | + const div = document.createElement('div') |
| 316 | + render(( |
| 317 | + <Link |
| 318 | + to='/foo' |
| 319 | + activeStyle={{ color: 'red' }} |
| 320 | + location={{ pathname: '/bar' }} |
| 321 | + /> |
| 322 | + ), div) |
| 323 | + expect(broadcasters.LocationSubscriber).toHaveBeenCalled() |
| 324 | + }) |
| 325 | + |
| 326 | + it('renders <LocationSubscriber> when props.children is a function', () => { |
| 327 | + const div = document.createElement('div') |
| 328 | + render(( |
| 329 | + <Link to='/foo' location={{ pathname: '/bar' }}> |
| 330 | + { |
| 331 | + ({isActive}) => <a className={isActive ? 'active' : ''}>Test!</a> |
| 332 | + } |
| 333 | + </Link> |
| 334 | + ), div) |
| 335 | + expect(broadcasters.LocationSubscriber).toHaveBeenCalled() |
| 336 | + }) |
| 337 | + |
| 338 | + it('does not render <LocationSubscriber> when it has no active props', () => { |
| 339 | + const div = document.createElement('div') |
| 340 | + render(( |
| 341 | + <Link to='/foo'>Foo</Link> |
| 342 | + ), div) |
| 343 | + expect(broadcasters.LocationSubscriber).toNotHaveBeenCalled() |
| 344 | + }) |
| 345 | + }) |
290 | 346 | })
|
0 commit comments