I had working jasmine tests with webpack 3. Now I try to use it with webpack 4 but have some problem with it.
Firstly I had problem with spyOn function.
Error: : myFunction is not declared writable or has no setter
I found some articles about some workaround for this problem: spy-on-getter-and-setter
I changed spyOn to spyOnProperty but with no luck. Now I have problem with
> Error: : myFunction is not declared configurable
My code is written in js and looks like this:
import * as FocusServiceSpy from '../focus/FocusService';
describe('#onLinkClick', function() {
it('should call myFunction', () => {
spyOnProperty(FocusServiceSpy, 'myFunction', 'get');
expect(FocusServiceSpy.myFunction).toHaveBeenCalled();
});
}
Do you know what could be a problem with this?
UPDATE 1:
I should be more descriptive. I would like to create spy on function of the FocusService. This service has only one method called myFunction. Only thing I want to achieve is to ensure that this method will be called.
Now I changed it to sth like this and have error:
>TypeError: Object is not a constructor (evaluating 'new FocusService()') (line 180)
describe('#onLinkClick', function() {
const FocusService = require('../focus/FocusService');
it('should call myFunction', () => {
const service = new FocusService();
spyOnProperty(service, 'myFunction').and.callThrough();
... (do some action)
expect(service.myFunction).toHaveBeenCalled();
});
}
FocusService looks like this:
export function myFunction(arg) {
... (do some action)
}
FocusService
is not a class, https://mcmap.net/q/135386/-using-jasmine-to-spy-on-a-function-without-an-object may give you some hint to solve your problem – Ormond