Skip to content

Instantly share code, notes, and snippets.

@johnnolan
Created February 25, 2019 16:18
Show Gist options
  • Save johnnolan/6b3d492e56215c5c6a243af62e302a6f to your computer and use it in GitHub Desktop.
Save johnnolan/6b3d492e56215c5c6a243af62e302a6f to your computer and use it in GitHub Desktop.
import React from "react";
import Button from "Button";
import { mountWrap } from 'contextWrap';
describe("Given the button is rendered with just a label", () => {
const data = {
label: "My Button"
}
let wrapper, aElement;
beforeEach(()=>{
wrapper = mountWrap(
<Button
label={data.label}
/>)
aElement = wrapper.find('button');
})
it('has one span and is populated correctly', () => {
expect(aElement).toHaveLength(1);
expect(aElement.hasClass('btn')).toBeTruthy();
});
});
import { BrowserRouter } from 'react-router-dom';
import { mount } from 'enzyme';
import { shape } from 'prop-types';
const router = {
history: new BrowserRouter().history,
route: {
location: {},
match: {},
},
};
const createContext = () => ({
context: { router },
childContextTypes: { router: shape({}) },
});
export function mountWrap(node) {
return mount(node, createContext());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment