jest-preset-angular: TypeError: (options.astTransformers || []).map is not a function angular 10
🐛 Bug Report
I have a unit test running using the
“jest”: “^26.4.2”, “jest-preset-angular”: “^8.3.1”, When I run the command npm run test:app it was working fine in Angular 8, now I have updated the angular to the latest version 10. I am getting an error as below on every test component
To Reproduce
Error log:
# content of error stacktrace :
TypeError: (options.astTransformers || []).map is not a function
at ConfigSet.get (node_modules/ts-jest/dist/config/config-set.js:225:64)
at ConfigSet.tsJest (node_modules/ts-jest/dist/util/memoize.js:43:24)
at ConfigSet.get (node_modules/ts-jest/dist/config/config-set.js:297:41)
at ConfigSet.versions (node_modules/ts-jest/dist/util/memoize.js:43:24)
at ConfigSet.get (node_modules/ts-jest/dist/config/config-set.js:588:32)
at ConfigSet.jsonValue (node_modules/ts-jest/dist/util/memoize.js:43:24)
at ConfigSet.get [as cacheKey] (node_modules/ts-jest/dist/config/config-set.js:603:25)
at TsJestTransformer.getCacheKey (node_modules/ts-jest/dist/ts-jest-transformer.js:126:36)
envinfo
System:
OS: Mac os Catalina
Npm packages:
"jest": "^26.4.2",
"jest-preset-angular": "^8.3.1",
"typescript": "~4.0.2"
describe(‘DateSelectionComponent’, () => { let component: DateSelectionComponent; let fixture: ComponentFixture<DateSelectionComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DateSelectionComponent, SafePipe],
imports: [
SharedModule,
NgReduxTestingModule,
RouterTestingModule.withRoutes([])
],
providers: [
{
provide: PageAPIActions, useValue: { setPageState() { } }
}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DateSelectionComponent);
component = fixture.componentInstance;
Object.defineProperties(component, {
page$: {
value: of('value'),
writable: true
},
page: {
value: { destination: 'value' },
writable: true
},
startDate: {
value: new NgbDate(2019, 2, 27),
writable: true
},
minDate: {
value: new NgbDate(2019, 2, 27),
writable: true
}
});
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('Should Match Snapshot', async () => {
(expect(fixture) as any).toMatchSnapshot();
});
});
Jest.app config
const baseConfig = require('./jest.base.config');
module.exports = {
...baseConfig,
roots: ['<rootDir>/src'],
modulePaths: ['<rootDir>/dist'],
modulePathIgnorePatterns: ['<rootDir>/src/app/shared'],
moduleNameMapper: {
"^@pts-ngx/core": "<rootDir>/dist/pts-ngx/core",
"^@pts-ngx/core/(.*)$": "<rootDir>/dist/pts-ngx/core/$1",
'projects/pts-ngx/core/(.*)$': '<rootDir>/projects/pts-ngx/core/$1'
}
};
Jest base config
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setupJest.ts'],
moduleNameMapper: {
"^@pts-ngx/core": "<rootDir>/dist/pts-ngx/core",
"^@pts-ngx/core/(.*)$": "<rootDir>/dist/pts-ngx/core/$1"
}
};
Jest.library config
// jest.lib.config.js
const baseConfig = require('./jest.base.config');
module.exports = {
...baseConfig,
roots: ['<rootDir>/projects'],
};
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
Seems to be a newer version of the package causing the issue.
In the
package.jsonI changed thejest-preset-angularfrom"8.3.2"to"8.2.0"and that error went away.this error is not
jest-preset-angularerror, this is fromjest. I would suggest you to Google this or ask in Jest discord channel. You can find jest Discord channel also via Google.