Currently using Jest with React-Router to validate and validate an element has href with the expected value.
following the instructions here
jest.dontMock('../BasicPage')
describe('BasicPage', function() {
let BasicPage = require('../BasicPage')
let TestUtils = require('react-addons-test-utils')
let ReactDOM = require('react-dom')
let React = require('react')
it('renders the Login button if not logged in', function() {
let page = TestUtils.renderIntoDocument(<BasicPage />)
let button = TestUtils.findRenderedDOMComponentWithTag(page, 'button')
expect(ReactDOM.findDOMNode(button).textContent).toBe('Login')
})
it('renders the Account button if logged in', function() {
let page = TestUtils.renderIntoDocument(<BasicPage authenticated={true} />)
let button = TestUtils.findRenderedDOMComponentWithTag(page, 'button')
expect(ReactDOM.findDOMNode(button).getAttribute('href')).toBe('/admin')
})
})
the element has a link like:
<Button bsStyle="primary"><Link to="/admin">Login</Link></Button>
when console.log'in on the href button is missing and the test returns null!
Has anyone found a way around this?
source
share