Created
February 25, 2019 16:18
-
-
Save johnnolan/6b3d492e56215c5c6a243af62e302a6f to your computer and use it in GitHub Desktop.
This file contains 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 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(); | |
}); | |
}); |
This file contains 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 { 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