2

我想知道是否有人使用 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

有人可以指出我有什么问题吗?

4

2 回答 2

2

看起来 Vue.js 目前不支持 storybook jest 插件 https://github.com/storybooks/storybook/blob/master/ADDONS_SUPPORT.md

于 2019-01-10T07:16:44.630 回答
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.results& options.results.testResults

有两种可能的解决方案:

  1. 使用适当版本的 Jest 和 storybook/addon-jest
  2. 在storybook-jest库的index.js中应用huck,像那样

    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
      });
    }
    
于 2019-01-18T08:15:43.733 回答