gpt4 book ai didi

typescript - Typescript 的 Jest 测试显示错误的错误行

转载 作者:搜寻专家 更新时间:2023-10-30 21:13:47 24 4
gpt4 key购买 nike

我正在一个结构上运行示例 Jest 测试,我发现 Jest 的输出摘要中的错误少了几行。

包.json

"devDependencies": {
"@types/jest": "^22.0.1",
"jest": "^22.1.4",
"jest-preset-angular": "^5.0.0",
"ts-jest": "^22.0.1",
"typescript": "^2.6.2"
},

输出:

Venue › Venue Structure › should have all the structure fields

expect(received).toBeDefined()

Expected value to be defined, instead received
undefined

20 | it('should be an instance of DataStructure', () => {
21 | expect(VenueInfo instanceof DataStructure).toBeTruthy();
> 22 | })
23 |
24 | it('should have the proper number of data fields', () => {
25 | expect(VenueInfo.NumberOfFields).toBe(14); // LastUpdated is added automatically

at src/structures/Venue.spec.ts:22:35

但是,根据 it() 中的文本,测试问题实际上位于第 29 行。

field .spec.ts:

import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';

import { Venue } from './Venue';
import { DataStructure } from '../library/base/DataStructure';

describe('Venue', () => {
let VenueInfo: Venue;

beforeEach(() => {
VenueInfo = new Venue();
});

describe('Class', () => {

it('should be an instance of Venue', () => {
expect(VenueInfo instanceof Venue).toBeTruthy(); ;
});

it('should be an instance of DataStructure', () => {
expect(VenueInfo instanceof DataStructure).toBeTruthy();
})

it('should have the proper number of data fields', () => {
expect(VenueInfo.NumberOfFields).toBe(14); });
});

describe('Venue Structure', () => {
it('should have all the structure fields', () => {
expect(VenueInfo.Key).toBeDefined();
expect(VenueInfo.Description).toBeDefined();
expect(VenueInfo.Address1).toBeDefined();
expect(VenueInfo.Address2).toBeDefined();
expect(VenueInfo.City).toBeDefined();
expect(VenueInfo.Province).toBeDefined();
expect(VenueInfo.Country).toBeDefined();
expect(VenueInfo.PostalCode).toBeDefined();
expect(VenueInfo.Telephone).toBeDefined();
expect(VenueInfo.Latitude).toBeDefined();
expect(VenueInfo.Longitude).toBeDefined();
expect(VenueInfo.MajorIntersection).toBeDefined();
expect(VenueInfo.DartBoards).toBeDefined();
});
});
});

tsconfig.json

{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMaps": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/**/*.spec.ts",
"src/test-config"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}

从早期的配置来看,我的 Ionic 应用程序的 src 目录中也有一个 tsconfig.spec.ts,它也有 sourceMaps: true,但似乎没有任何影响。

tsconfig.spec.json(不确定是什么用途,因为我找不到对该文件的引用):

{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowJs": true,
"module": "commonjs",
"outDir": "../out-tsc/spec",
"sourceMaps": true,
"target": "es5"
},
"files": [
"**/*.ts"
],
"include": [
"*.spec.ts",
"**/*.spec.ts",
"**/*.d.ts",
"test-config/*.ts",
"test-config/**/*.ts"
]
}

最佳答案

Jest test of Typescript shows wrong error lines

确保你的 tsconfig.jsonsourceMap: true

关于typescript - Typescript 的 Jest 测试显示错误的错误行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48412159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com