Skip to content

Instantly share code, notes, and snippets.

@ricca509
Last active July 18, 2016 21:46
Show Gist options
  • Save ricca509/bec0f194dacd7d66f39a1cb7b7e135a4 to your computer and use it in GitHub Desktop.
Save ricca509/bec0f194dacd7d66f39a1cb7b7e135a4 to your computer and use it in GitHub Desktop.
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