Last active
October 2, 2017 03:20
-
-
Save Calvin-Huang/a0e42e579e43e5fde37f211b51ac367b 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 configureMockStore from 'redux-mock-store'; | |
import middleware from './middleware'; | |
import actions, { types } from './actions'; | |
describe('test middleware behavior', () => { | |
// Mock jQuery. | |
class jQuery { | |
constructor(selector, context) { } | |
html() { } | |
find() { return this; } | |
modal() { return this; } | |
text() {} | |
} | |
describe('when the network request is fine', () => { | |
const $ = (selector, context) => new jQuery(selector, context); | |
$.templates = () => ({ render: () => { } }); | |
$.ajax = () => { }; | |
const mockStore = configureMockStore([middleware(types, actions, $)]); | |
it('createBookmark action should triggers bookmarkCreated and setReposAreSaved action', () => { | |
const store = mockStore({ | |
repos: { page: 1, data: [{ id: 1, full_name: 'foo/boo' }] }, | |
bookmarks: [], | |
}); | |
const expectedActions = [ | |
actions.createBookmark(1, 'foo/boo'), | |
actions.bookmarkCreated(1, 'foo/boo'), | |
// There is no reducer included, so bookmarks array stil is empty. | |
actions.setReposAreSaved([]), | |
]; | |
store.dispatch(expectedActions[0]); | |
expect(store.getActions()).toEqual(expectedActions); | |
}); | |
... | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment