I am running a sample Jest test on a structure, and I find that the errors in my output summary from Jest are off by a couple of lines.
Package.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"
},
Output:
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
However, the test is question is actually at line 29, based on the text from the it().
Venue.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
}
}
From early configurations, I also had a tsconfig.spec.ts in the src directory of my Ionic application, which also has the sourceMaps: true, but does not seem to have any impact.
tsconfig.spec.json (not sure what uses this as I cannot find a reference to the file):
{
"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
Make sure your tsconfig.json has sourceMap: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With