It is not possible anymore to spy on individually exported functions.
https://github.com/jasmine/jasmine/issues/1414
There are some workarounds that might work, but there isn’t a “works for all” solution.
Quoting from above link:
Actually setting “module”: “commonjs” in tsconfig.json for tests fixes this issue and you can use spyOn again.
For me, this didn’t work. Jasmine needs a place to put the spy in, so I created a Wrapper class so that the spy is installed on that class instead of the module.
import { supportsScrollBehavior as cdkSupportsScrollBehavior} from '@angular/cdk/platform';
export class CdkWrapper {
public static supportsScrollBehavior(...args) {
return cdkSupportsScrollBehavior(...args);
}
}
Which you use like this in the spec file:
spyOn(CdkWrapper , 'supportsScrollBehavior').and.returnValue(true);
Remember to also use that wrapper in the component you are testing!
CdkWrapper.supportsScrollBehavior()