I'm getting the infamous "Jest encountered an unexpected token" error while trying to test an Angular component in an nx workspace. It is particularly frustrating because the error is happening when trying to import @angular/cdk/a11y, which is a public interface from an official package from the Angular team.
Anyway, the best resource about this problem that I could find is this issue on Github, which wasn't very helpful. https://github.com/nrwl/nx/issues/1091 It led me to try adding different things to the transformIgnorePatterns property in my jest.config.js. None of which solved the problem.
When trying variation of this:
transformIgnorePatterns: ['node_modules/(?!@angular/cdk)'],
It seemed to resolve the "unexpected token" issue but then I end up with a bunch of "This constructor is not compatible with Angular Dependency Injection because its dependency at index 1 of the parameter list is invalid. This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator." errors.
Any help will be greatly appreciated.