-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discussion]Support jest.useFakeTimers and fakeAsync() #520
Comments
I left a comment for that PR. In general, |
This solve my issues with fakeAsync and rxjs. Thanks! |
I saw that this is already merged with Angular. But my issue is, that the example test provided in this thread does not work for me. could it be reagarding my module.exports = {
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
useESM: true,
tsconfig: '<rootDir>/src/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
},
moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
moduleNameMapper: {
'@shared/(.*)': '<rootDir>/src/app/shared/$1',
},
transform: {
'^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular',
},
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts', 'jest-extended/all', 'jest-marbles'],
reporters: ['jest-spec-reporter'],
transformIgnorePatterns: [`<rootDir>/node_modules/(?!.*\\.mjs$|${['@angular', '@ngrx', 'd3'].join('|')})`],
}; |
any updates on this? |
I have tried this as well, and I'm pretty sure it doesn't work any more. Or at least, it doesn't work for ESM tests. You could try switching to CJS/non ESM mode and see if it works in that scenario with latest dependencies. Or you could just add |
I already use |
I created a PR in the angular repo angular/angular#39016 to support integration between
fake timer APIs
of jest andfakeAsync()
.Any feedback is appreciate!
After enable this feature, calling
jest.useFakeTimers()
will make all testrun into
fakeAsync()
automatically.Also there are mappings between
jest
andzone
APIs.jest.runAllTicks()
will callflushMicrotasks()
.jest.runAllTimers()
will callflush()
.jest.advanceTimersByTime()
will calltick()
jest.runOnlyPendingTimers()
will callflushOnlyPendingTimers()
jest.advanceTimersToNextTimer()
will calltickToNext()
jest.clearAllTimers()
will callremoveAllTimers()
jest.getTimerCount()
will callgetTimerCount()
For detail usage, please refer to the test file
https://github.com/angular/angular/pull/39016/files#diff-53fe8d9816dc08e106333ff822445d7fR103-R413
The text was updated successfully, but these errors were encountered: