Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit 59f76f8

Browse files
committed
Fixed the problem of mapMutations, mapGetters, mapActions with vuex
1 parent 97d325e commit 59f76f8

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-docgen-api",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Toolbox to extract information from Vue component files for documentation generation purposes.",
55
"bugs": {
66
"url": "https://github.com/vue-styleguidist/vue-docgen-api/issues"
@@ -32,6 +32,7 @@
3232
"babel-preset-env": "^1.5.2",
3333
"babel-preset-es2015": "^6.24.1",
3434
"babel-preset-flow": "^6.23.0",
35+
"babel-preset-stage-2": "^6.24.1",
3536
"doctrine": "^2.0.0",
3637
"enhanced-require": "^0.5.0-beta6",
3738
"hash-sum": "^1.0.2",

src/utils/getSandbox.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import getDocFile from './getDocFile';
21
import stateDoc from './stateDoc';
32
const babel = require('babel-core');
43
const fs = require('fs');
@@ -10,7 +9,7 @@ const babelifyCode = code => {
109
const options = {
1110
ast: false,
1211
comments: false,
13-
presets: ['babel-preset-es2015'],
12+
presets: ['babel-preset-es2015', 'babel-preset-stage-2'],
1413
};
1514
return babel.transform(code, options);
1615
};
@@ -68,7 +67,15 @@ const evalComponentCode = (code) => {
6867
exports: {
6968
},
7069
},
71-
require:()=> {
70+
require:(element)=> {
71+
if (element === 'vuex') {
72+
return {
73+
mapState: function(){},
74+
mapMutations: function(){},
75+
mapGetters: function(){},
76+
mapActions: function(){}
77+
}
78+
}
7279
return function(){}
7380
},
7481
document: {},

tests/components/vuex/example.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
</template>
3+
<script>
4+
import {mapGetters} from 'vuex'
5+
/**
6+
* Partial mapping, object spread operator example
7+
*/
8+
export default {
9+
name: 'example',
10+
computed: {
11+
total () {
12+
return this.$store.getters.allCustomers.length
13+
},
14+
...mapGetters({
15+
duplicate: 'hasDuplicateCustomer',
16+
characters: 'alphaKeys'
17+
})
18+
},
19+
mounted () {
20+
console.log('Second component loaded')
21+
}
22+
}
23+
</script>

tests/parse.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ const path = require('path');
22
var api = require('../dist/main');
33
var grid = path.join(__dirname, './components/grid/Grid.vue');
44
var button = path.join(__dirname, './components/button/Button.vue');
5+
var exampleVuex = path.join(__dirname, './components/vuex/example.vue');
56
const expect = require("chai").expect;
67
let docGrid;
78
let docButton;
89

9-
describe('tests lite grid', () => {
10+
describe('tests grid', () => {
1011
docGrid = api.parse(grid);
1112

1213
it('should return an object', () => {
@@ -54,9 +55,9 @@ describe('tests lite grid', () => {
5455
})
5556
})
5657

57-
describe('tests lite button', () => {
58+
describe('tests button', () => {
5859
docButton = api.parse(button);
59-
console.log(JSON.stringify(docButton, null, 2));
60+
// console.log(JSON.stringify(docButton, null, 2));
6061

6162
it('should return an object', () => {
6263
expect(docButton).to.be.an('object')
@@ -102,3 +103,19 @@ describe('tests lite button', () => {
102103
expect(Object.keys(docButton['props']).length).to.equal(4)
103104
})
104105
})
106+
107+
describe('test example vuex', () =>{
108+
const docVuex = api.parse(exampleVuex);
109+
110+
it('should return an object', () => {
111+
expect(docVuex).to.be.an('object')
112+
})
113+
114+
it('The component name should be example', () => {
115+
expect(docVuex.displayName).to.equal('example');
116+
})
117+
118+
it('The component should have a description', () => {
119+
expect(docVuex.description).to.equal('Partial mapping, object spread operator example');
120+
})
121+
})

0 commit comments

Comments
 (0)