Last active
July 27, 2017 14:33
-
-
Save sandwichsudo/7a202a7f943c6551e3ec1dbb7b96ee3c to your computer and use it in GitHub Desktop.
Test for calling API when component mounts
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
// src/containers/RepoSearchPage/page/RepoSearchPage.js | |
// export the class to test in isolation | |
export class RepoSearchPage extends Component { | |
constructor(props) { | |
super(props); | |
} | |
... | |
} |
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
// src/containers/RepoSearchPage/page/RepoSearchPage.spec.js | |
import React from 'react'; | |
import { mount } from 'enzyme'; | |
import { RepoSearchPage } from './RepoSearchPage'; | |
describe('<RepoSearchPage />', () => { | |
let props = {}; | |
let repoDataMock = { | |
name: 'foo', | |
id: 'bar', | |
stargazers_count: '5' | |
}; | |
beforeEach(() => { | |
props = { | |
actions: { | |
fetchRepos: jest.fn(), | |
}, | |
searchResults: [ repoDataMock ] | |
}; | |
}); | |
describe('componentWillMount', () => { | |
it('should call fetchRepos', () => { | |
mount(<RepoSearchPage {...props} />); | |
expect(props.actions.fetchRepos).toHaveBeenCalled(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment