Vue.js (2) actions coverage incomplete after unit test -


using vue.js 2 , vue-resource

after running correctly unit test, coverage incomplete can see in lcov-report/src/vuex/actions.js.html ..,

return api.addnewshoppinglist(shoppinglist)  

is executed (1x), not code inside .then() block

thanks can give me feedback on issue? ( if it's issue.. or normal behavior )

actions.spec.js

    import actions '@/vuex/actions'     import * types '@/vuex/mutation_types'      describe('actions.js', () => {       var server, store, lists, successpost        successpost = {'post': true}        beforeeach(() => {         // mock shopping lists         lists = [{           id: '1',           title: 'groceries'         }, {           id: '2',           title: 'clothes'         }]          // mock store commit , dispatch methods         store = {           commit: (method, data) => {},           dispatch: () => {             return promise.resolve() // static method           },           state: {             shoppinglists: lists           }         }         sinon.stub(store, 'commit')         // mock server         server = sinon.fakeserver.create()         server.respondwith('post', /shoppinglists/, xhr => {           xhr.respond(200, {'content-type': 'application/json'}, json.stringify(successpost))         })         server.autorespond = true       })        aftereach(() => {         store.commit.restore()         server.restore()       })        describe('createshoppinglist', () => {         it('should return successful post response', () => {           let newlist = { title: 'new list', id: '3' }           actions.createshoppinglist(store, newlist).then((resp) => {             expect(resp.body).to.eql(successpost)           })         })       })     }) 

actions.js

    import * types './mutation_types'     import api '../api'     import getters './getters'      export default {       populateshoppinglists: ({ commit }) => {         return api.fetchshoppinglists().then(response => {           commit(types.populate_shopping_lists, response.data)         })       },       createshoppinglist: (store, shoppinglist) => {         return api.addnewshoppinglist(shoppinglist)         .then(() => {           store.commit(types.add_shopping_list, shoppinglist)           store.dispatch('populateshoppinglists')         })       },     } 

api/index.js

    import vue 'vue'     import vueresource 'vue-resource'      vue.use(vueresource)      const shoppinglistsresource = vue.resource('http://localhost:3000/' + 'shoppinglists{/id}')      export default {       addnewshoppinglist: (data) => {         return shoppinglistsresource.save(data)       }     } 

mutations.js

    import * types './mutation_types'     import getters './getters'     import _ 'underscore'      export default {       [types.populate_shopping_lists] (state, lists) {         state.shoppinglists = lists       },       [types.add_shopping_list] (state, newlist) {         if (_.isobject(newlist)) {           state.shoppinglists.push(newlist)         }       }     } 

mutations.types

    export const populate_shopping_lists = 'populate_shopping_lists'     export const add_shopping_list = 'add_shopping_list' 

getters.js

    import _ 'underscore'      export default {       getlists: state => state.shoppinglists,     } 

console

    mymac:lcov-report yves$ npm run unit      > shopping-list@1.0.0 unit /users/yves/developments/shopping-list     > cross-env babel_env=test karma start test/unit/karma.conf.js --single-run      [karma]: karma v1.7.1 server started @ http://0.0.0.0:9876/     [launcher]: launching browser phantomjs unlimited concurrency     launcher]: starting browser phantomjs     [phantomjs 2.1.1 (mac os x 0.0.0)]: connected on socket -xte5wwpbnsfatg_aaaa id 73492961        actions.js         ...         createshoppinglist           ✓ should return successful post response      phantomjs 2.1.1 (mac os x 0.0.0): executed 13 of 13 success (0.086 secs / 0.034 secs)     total: 13 success      =============================== coverage summary ==================     statements   : 64.44% ( 29/45 )     branches     : 50% ( 2/4 )     functions    : 81.25% ( 13/16 )     lines        : 64.44% ( 29/45 )     ================================================================ 

lcov-report/src/vuex/actions.js.html

      import * types './mutation_types'       import api '../api'       import getters './getters'        export default {          createshoppinglist: (store, shoppinglist) => {     **1×    return api.addnewshoppinglist(shoppinglist)**           .then(() => {             store.commit(types.add_shopping_list, shoppinglist)             store.dispatch('populateshoppinglists')           })         },       } 


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -