mutations.spec.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Created by zhengguorong on 2016/11/30.
  3. */
  4. import { expect } from 'chai'
  5. import mutations from 'src/vuex/article/mutations'
  6. import Article from 'src/model/Article'
  7. describe('article mutations', () => {
  8. const state = {
  9. // 文章列表
  10. list: [],
  11. // 正在编辑的文章
  12. editorArticle: {}
  13. }
  14. const articleList = []
  15. const articleOne = new Article()
  16. const articleTwo = new Article()
  17. articleList.push(articleOne)
  18. articleList.push(articleTwo)
  19. it('获取文章列表', () => {
  20. mutations.GET_ARTICLE_LIST(state, articleList)
  21. expect(state.list.length).to.equal(2)
  22. })
  23. it('文章列表倒序获取', () => {
  24. expect(state.list[0]).to.equal(articleTwo)
  25. })
  26. it('添加文章', () => {
  27. let oldLength = state.list.length
  28. mutations.ADD_ARTICLE(state, new Article())
  29. expect(state.list.length).to.equal(oldLength + 1)
  30. })
  31. it('设置正在编辑文章', () => {
  32. mutations.SET_EDITOR_ARTICLE(state, articleOne)
  33. expect(state.editorArticle).to.equal(articleOne)
  34. })
  35. })