Last active
July 18, 2016 21:46
-
-
Save ricca509/bec0f194dacd7d66f39a1cb7b7e135a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react'; | |
import { shallow } from 'enzyme'; | |
import proxyquire from 'proxyquire'; | |
proxyquire.noCallThru(); | |
const Header = () => <div></div>; // stub component | |
const Sidebar = () => <div></div>; // stub component | |
const Footer = () => <div></div>; // stub component | |
const Oops = () => <div></div>; // stub component | |
// Require the component to test (HomePage) through proxyquire | |
// and pass it the stubbed dependencies | |
const HomePage = proxyquire('../components/HomePage', { | |
'./Header': Header, | |
'./Sidebar': Sidebar, | |
'./Footer': Footer, | |
'./Oops': { Oops } | |
}).default; | |
describe('The HomePage component', function () { | |
describe('when there is no error', function () { | |
it('should render the page', function () { | |
const props = { | |
data: { | |
links: '' | |
} | |
}; | |
const output = shallow(<HomePage {...props} />); | |
expect(output.find(Header)).to.have.lengthOf(1); | |
expect(output.find(Sidebar)).to.have.lengthOf(1); | |
expect(output.find(Footer)).to.have.lengthOf(1); | |
expect(output.find(Oops)).to.have.lengthOf(0); | |
}); | |
}); | |
describe('when there is an error', function () { | |
it('should render the Oops', function () { | |
const props = { | |
error: { | |
message: 'blown up' | |
} | |
}; | |
const output = shallow(<HomePage {...props} />); | |
expect(output.find(Header)).to.have.lengthOf(0); | |
expect(output.find(Sidebar)).to.have.lengthOf(0); | |
expect(output.find(Footer)).to.have.lengthOf(0); | |
expect(output.find(Oops)).to.have.lengthOf(1); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment