如何在Jest测试中导入JSON文件? [英] How to import JSON file on Jest tests?
本文介绍了如何在Jest测试中导入JSON文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Jest
测试我的应用程序,但它收到如下错误:
I'm testing my application using Jest
, but it's getting an error like:
SyntaxError: Unexpected token }
行发生的错误是:
import { something } from "../my-json.json";
如何导入 JSON
文件Jest测试?
How can I import the JSON
file on Jest tests?
推荐答案
你需要从'filename.json'导入json
。确保如果您使用路径别名,则需要在 ModuleNameMapper $ c $中的
jest.config.js
文件中配置它们。 c>配置。
You need to import json from 'filename.json'
. Make sure that if you're using path alias you need to configure them on your jest.config.js
file inside the ModuleNameMapper
config.
这篇关于如何在Jest测试中导入JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文