找不到模块“ pie-react-assets”

时间:2019-09-11 05:03:50

标签: reactjs typescript jestjs gatsby ts-jest

我正在尝试运行测试脚本。我运行npm test的那一刻,在所有测试案例中,都会发生以下错误:

错误:

  

无法从'footer.tsx'中找到模块'pie-react-assets'“ FAIL src / tests /footer.test.tsx测试套件无法运行无法找到模块'pie-react-资产”来自“ footer.tsx”,但是Jest能够找到:“ ../ components / footer.tsx”


您可能想在导入文件中包含文件扩展名,或者更新moduleFileExtensions(当前为['ts', 'tsx', 'js', 'json'])。

  1 | import { Link } from "gatsby"
  2 | import React from "react"
> 3 | import { Footer as PieFooter } from 'pie-react-assets'

//项目配置:ReactJS类型脚本gatsby

// i已经包含在jest.config.js中

moduleFileExtensions: [
    "ts",
    "tsx",
    "js",
    "json",
]

// PAckage.json  //“ test”:“ jest --config jest.config.js”

// footer.tsx

import { Link } from "gatsby"
import React from "react"
import { Footer as PieFooter } from 'pie-react-assets'

const Footer = () => {
  const links = [
    { label: 'xxxxx', link: 'xxxxxxx' },
    { label: 'xxxxx', link: 'xxxxxxxxx }
  ]

  return (<footer>
      <div className={`footer-container`}>
          <PieFooter links={links} />
      </div>
  </footer>)
}

导出默认页脚

// footer.test.tsx

import React from "react"
import { render } from "@testing-library/react"
import Footer from "../components/footer"

describe("Footer", () => {
  it("renders correctly", () => {
    const tree = renderer
      .create(<Footer siteTitle="xxxxx" />)
      .toJSON()
    expect(tree).toMatchSnapshot()
  })
})

0 个答案:

没有答案