aurelia / aurelia/http-client-mock
createCustomEvent is not a function Error
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
**I'm submitting a bug report**
* **Library Version:**
^0.1.0
* **Operating System:**
Windows 10
* **Node Version:**
9.5.0
* **NPM Version:**
5.6.0
* **JSPM OR Webpack AND Version**
WEbpack 3.5.5
* **Browser:**
Chrome
* **Language:**
TypeScript >=1.9.0-dev || ^2.0.0
Karma ^0.13.22
Jasmine-core ^2.4.1
**Current behavior:**
Writing unit tests and setting up the httpClientMock to return expected post behavior from a given URL, then inject the mock into a service that is being tested causes the following error message:
TypeError: __WEBPACK_IMPORTED_MODULE_1_aurelia_pal__.b.createCustomEvent is not a function
at trackRequestEnd (webpack-internal:///14:700:72)
at eval (webpack-internal:///14:764:9)
From previous event:
at eval (webpack-internal:///14:763:15)
From previous event:
at HttpClientMock.send (webpack-internal:///14:755:47)
at RequestBuilder.send (webpack-internal:///14:682:24)
at HttpClientMock.post (webpack-internal:///14:813:66)
at DocumentService.postReviewInterfaceDataRequest (webpack-internal:///36:4:39477)
at UserContext.eval (webpack-internal:///128:74:13)
at attempt (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4486:26)
at QueueRunner.run (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4402:20)
at QueueRunner.execute (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4384:10)
at Spec.queueRunnerFactory (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:964:35)
at Spec.execute (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:563:10)
at UserContext.fn (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5541:37)
at attempt (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4486:26)
at QueueRunner.run (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4402:20)
at runNext (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4446:20)
at http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4453:13
at http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4356:12
at QueueRunner.complete [as onComplete] (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:570:9)
at http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4416:12
at MessagePort.channel.port1.onmessage (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1849:11)
**Expected/desired behavior:**
It works fine when not injecting, we tested even injecting into a simple service that just creates the post and returns the response and we still get the error.
Test:
```
it("postReviewInterfaceDataRequest returns ReviewInterfaceData", done => {
const response: ReviewInterfaceData = {
WorkspaceName: "Test",
Permissions: null,
DocumentData: null,
};
const request: ReviewInterfaceDataRequest = new ReviewInterfaceDataRequest();
httpMock.expect(url)
.withMethod("POST")
.withResponseStatus(200)
.withResponseBody(response);
sut = new DocumentService(logManagerMock.object, httpMock, url);
sut.postReviewInterfaceDataRequest(request)
.then(data => {
expect(data).toEqual(response);
done();
});
});
```
Service:
```
import { inject, LogManager } from "aurelia-framework";
import { HttpClient, HttpResponseMessage } from "aurelia-http-client";
import { Logger } from "aurelia-logging";
/**
* Document service for retrieving document data from server
*/
@inject(LogManager, HttpClient)
export class DocumentService {
public logger: Logger;
public http: HttpClient;
public url: string;
/**
* Constructor
* @param {LogManager} logManager Aurelia Log Manager
* @param {HttpClient} http Aurelia Http Client
*/
constructor(logManager, http: HttpClient, url: string) {
this.logger = logManager.getLogger("Document Service");
this.http = http;
this.url = url;
}
/**
* posts the request for the review interface data request
* @param {ReviewInterfaceDataRequest} request the ReviewInterfaceDataRequest to post
* @returns {Promise} a promise for the review interface data response from the post call
*/
public postReviewInterfaceDataRequest(request): Promise {
return this.http.post(this.url, request);
}
}
```
Contributor guide
Research direction
Start with the HttpClientMock.send and trackRequestEnd entries in the stack trace, then reproduce the documented Jasmine test with the injected mock and POST request. Done means the test completes without the createCustomEvent TypeError and the returned data equals the expected response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript, webpack
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100