-
-
Save chudaol/addb6657095406234bc6f659970f3eb8 to your computer and use it in GitHub Desktop.
Asynchronous test that tests dispatch method being called with mocked server's response
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 actions from 'src/vuex/actions' | |
import { CHANGE_TITLE, POPULATE_SHOPPING_LISTS, ADD_SHOPPING_LIST, DELETE_SHOPPING_LIST } from 'src/vuex/mutation_types' | |
describe('actions.js', () => { | |
var lists, store, server | |
beforeEach(() => { | |
// mock shopping lists | |
lists = [{ | |
id: '1', | |
title: 'Groceries' | |
}, { | |
id: '2', | |
title: 'Clothes' | |
}] | |
// mock store commit method | |
store = { | |
commit: (method, data) => {}, | |
state: { | |
shoppinglists: lists | |
} | |
} | |
sinon.stub(store, 'commit') | |
// mock server | |
server = sinon.fakeServer.create() | |
server.respondWith('GET', /shoppinglists/, xhr => { | |
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(lists)) | |
}) | |
server.autoRespond = true | |
}) | |
afterEach(() => { | |
// restore stubs and server mock | |
store.commit.restore() | |
server.restore() | |
}) | |
describe('populateShoppingLists', () => { | |
it('should call commit method with POPULATE_SHOPPING_LIST string parameter', done => { | |
actions.populateShoppingLists(store).then(() => { | |
expect(store.commit).to.have.been.calledWith(POPULATE_SHOPPING_LISTS, lists) | |
done() | |
}).catch(done) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment