I've been facing issues trying to run my Jasmine test suite with webpack 4. Ever since I upgraded webpack, I keep getting this error message in almost every test:
Error: <spyOn> : getField is not declared writable or has no setter
The problem seems to stem from a common pattern we follow for creating spies on simple functions, like so:
import * as mod from 'my/module';
//...
const funcSpy = spyOn(mod, 'myFunc');
I have experimented with module.rules[].type
, but none of the available options seem to solve the issue.
According to this webpack GitHub issue, ECMA modules are designed to be non-writable, which makes sense for web usage. But is there really no workaround for running tests?
Here are the relevant package versions:
"jasmine-core": "2.6.4",
"typescript": "2.5.3",
"webpack": "4.1.1",
"webpack-cli": "^2.0.12",
"karma": "^0.13.22",
"karma-jasmine": "^1.1.0",
"karma-webpack": "^2.0.13",