I’m trying to create a unit test case using Karma and Jasmine. I’m using jasmine-ajax to stub out the API request with a fake response. But the problem I have is that the unit test throws an error saying “TypeError: aurelia_pal__WEBPACK_IMPORTED_MODULE_1__.DOM.createCustomEvent is not a function”.
The unit test:
import { SystemInfo } from './../../src/common/models/system-info';
import { InfoPresentation } from "applications/info_presentation/info-presentation";
describe('Info presentation:', () => {
let _infoPresentationViewModel: InfoPresentation;
beforeEach(() => {
jasmine.Ajax.install();
_infoPresentationViewModel = new InfoPresentation();
})
afterEach(() => {
jasmine.Ajax.uninstall();
})
describe('when the info is retrieved', () => {
let _expectedValue: Collections.Set<SystemInfo>;
beforeEach(() => {
jasmine.Ajax.stubRequest('https://someurl/api/info').andReturn({
status: 200,
responseText: '[{"id":1, "infoText": "Updated"}]'
});
_expectedValue = new Collections.Set<SystemInfo>();
_expectedValue.add(Object.assign(new SystemInfo(), {
id: 1,
infoText: "Updated",
}));
})
it('then should be presented on the page', () => {
_infoPresentationViewModel.startRetrievingSystemInfos();
expect(_infoPresentationViewModel.SystemInfos).toEqual(_expectedValue);
})
})
})
The view model:
import * as Collections from 'typescript-collections';
import { SystemInfo } from 'common/models/system-info';
import { HttpClient } from 'aurelia-http-client';
export class InfoPresentation {
SystemInfos: Collections.Set<SystemInfo>;
private _http: HttpClient;
constructor() {
this._http = new HttpClient().configure(config => {
config.withHeader('Content-Type', 'application/json')
});
}
attached() {
this.startRetrievingSystemInfos();
}
public startRetrievingSystemInfos() {
this._http.get('https://someurl/api/info')
.then(result => {
console.log(result);
})
.catch(error => {
console.log(error);
})
}
}
Any ideas what is the problem?