Vue Storybook Jest Addon配置问题

时间:2018-10-01 10:12:11

标签: vue.js jestjs storybook

我想知道使用jest插件的人是否可以共享它的Vue Storybook配置,因为我似乎无法使其工作。我已经尝试了全局模式:

在Storybook的config.js中:

import { withTests } from '@storybook/addon-jest';

import results from '../.jest-test-results.json';

addDecorator(
  withTests({
    results,
  })
);

在我的故事中:

storiesOf('Elements/Tag', module)
  .addParameters({ jest: ['ThuleTag'] })
  .addDecorator(VueInfoAddon)
  .addDecorator(withTests({ results })('ThuleTag'))
  .add('Squared',
    withNotes(_notes)(() => ({
      components: {ThuleTag},
      template: _template,
      propsDescription: {
        size: 'medium / small / mini',
        type: 'success / info/warning / danger'
      }
    })),
  )

我收到此错误:

TypeError: Object(...)(...).addParameters is not a function

我也尝试了本地方式: 在我的故事中:

import { storiesOf } from '@storybook/vue'
import { withNotes } from '@storybook/addon-notes'
import results from '../../../jest-test-results.json'
import { withTests } from '@storybook/addon-jest'
import ThuleTag from '../../components/ui/elements/ThuleTag.vue'

let _notes = `A simple wrapper for the Elements el-tag, that accepts the same <i>type</i> and <i>size</i> props`

let _template = `<thule-tag
  size="small"
  key="name">Tag Namez
</thule-tag>`

storiesOf('Elements/Tag', module)
  .addDecorator(withTests({ results }))
  .add('Squared',
    withNotes(_notes)(() => ({
      components: {ThuleTag},
      template: _template,
      propsDescription: {
        size: 'medium / small / mini',
        type: 'success / info/warning / danger'
      }
    })),
    {
      jest: ['ThuleTag.test.js'],
    }
  )

我在这里收到此错误:

Error in render: "TypeError: Cannot read property '__esModule' of undefined"

“测试”选项卡显示以下消息:

This story has tests configured, but no file was found

有人可以指点我什么事吗?

2 个答案:

答案 0 :(得分:1)

目前看来Vue.js不支持故事书开玩笑的插件 https://github.com/storybooks/storybook/blob/master/ADDONS_SUPPORT.md

答案 1 :(得分:0)

好的,关于第一个错误

Error in render: "TypeError: Cannot read property '__esModule' of undefined"

我认为您应该检查babel-config,看来您忘记了框架的一些预设。

关于第二个问题

This story has tests configured, but no file was found

该问题发生在Jest,并且storybook / addon-jest希望使用equals api获得,但事实并非如此。在最新版本的Jest中,输出文件结构具有options.testResults,但storybook / addon-jest需要options.resultsoptions.results.testResults

有两种可能的解决方案:

  1. 使用适当版本的Jest和storybook / addon-jest
  2. 将故事应用到Storybook-Jest库的index.js中,像这样

    if (testFiles && !testFiles.disable) {
      //todo: HERE should be your storybook hack
      options.results = options.tests.testResults;
      options.results.testResults = options.results;
        emitAddTests({
        kind: kind,
        story: story,
        testFiles: testFiles,
        options: options
      });
    }