将Jest与Typescript一起使用时的透明度
当我在Typescript项目中使用Jest启动测试套件时,出现以下编译错误: 类型错误: /路径/instant.ts: 无法读取未定义的属性“some” 在my package.json中,我有以下Jest配置:将Jest与Typescript一起使用时的透明度,typescript,jestjs,Typescript,Jestjs,当我在Typescript项目中使用Jest启动测试套件时,出现以下编译错误: 类型错误: /路径/instant.ts: 无法读取未定义的属性“some” 在my package.json中,我有以下Jest配置: "jest": { "preset": "react-native", "transform": { "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/src/__tests__/.*|(\\.|/)
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/src/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"collectCoverage": true,
"coverageReporters": [
"json",
"html"
]
}
Instant.ts:
export class Instant {
constructor(private id: string,
private name: string) {
}
}
和instant.js:
export class Instant {
constructor(id, name) {
this.id = id;
this.name = name;
}
}
//# sourceMappingURL=instant.js.map
我分享我自己的Jest配置,它为我工作:
{
preset: 'react-native',
rootDir: '..',
setupFiles: [
'<rootDir>/configuration/jest.setup.js'
],
moduleFileExtensions: [
'ts',
'tsx',
'js'
],
transform: {
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
'\\.(ts|tsx)$': 'ts-jest'
},
testMatch: [
'<rootDir>/__tests__/**/?(*.)+(spec|test).ts?(x)'
],
testPathIgnorePatterns: [
'\\.snap$',
'<rootDir>/node_modules/'
],
collectCoverageFrom: [
'<rootDir>/src/**/*.{ts,tsx}'
],
coveragePathIgnorePatterns: [
'<rootDir>/__tests__/'
],
coverageDirectory: '<rootDir>/jest/coverage',
coverageReporters: [
'html',
'text',
'text-summary'
]
}
{
预设:“反应本机”,
rootDir:“…”,
设置文件:[
“/configuration/jest.setup.js”
],
moduleFileExtensions:[
"ts",,
“tsx”,
“js”
],
转换:{
“^.+\.js$”:“/node\u modules/react native/jest/preprocessor.js”,
“\\(ts | tsx)$”:“ts笑话”
},
测试匹配:[
“/”测试“/”/**/?(*)+(规范测试).ts?(x)“
],
testPathIgnorePatterns:[
“\\.snap$”,
“/node_modules/”
],
收款人:[
“/src/***.{ts,tsx}”
],
Coverage PathIgnorePatterns:[
“/”测试“/”
],
coverage目录:'/jest/coverage',
搬运工:[
“html”,
“文本”,
“文本摘要”
]
}
我想我们需要从即时查看一些代码。ts
@Fenton我更新了我的问题在你的代码中没有一些
。我的代码中没有“一些”