-
Notifications
You must be signed in to change notification settings - Fork 27.2k
fix(common): canceled JSONP requests won't throw error with missing callback function #36807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,15 +17,14 @@ function runOnlyCallback(home: any, data: Object) { | |
| const keys = Object.keys(home); | ||
| expect(keys.length).toBe(1); | ||
| const callback = home[keys[0]]; | ||
| delete home[keys[0]]; | ||
| callback(data); | ||
| } | ||
|
|
||
| const SAMPLE_REQ = new HttpRequest<never>('JSONP', '/test'); | ||
|
|
||
| { | ||
| describe('JsonpClientBackend', () => { | ||
| let home = {}; | ||
| let home: any; | ||
| let document: MockDocument; | ||
| let backend: JsonpClientBackend; | ||
| beforeEach(() => { | ||
|
|
@@ -63,6 +62,20 @@ const SAMPLE_REQ = new HttpRequest<never>('JSONP', '/test'); | |
| }); | ||
| document.mockError(error); | ||
| }); | ||
| it('prevents the script from executing when the request is cancelled', () => { | ||
| const sub = backend.handle(SAMPLE_REQ).subscribe(); | ||
| expect(Object.keys(home).length).toBe(1); | ||
| const keys = Object.keys(home); | ||
| const spy = jasmine.createSpy('spy', home[keys[0]]); | ||
|
|
||
| sub.unsubscribe(); | ||
| document.mockLoad(); | ||
| expect(Object.keys(home).length).toBe(0); | ||
|
||
| expect(spy).not.toHaveBeenCalled(); | ||
| // The script element should have been transferred to a different document to prevent it from | ||
| // executing. | ||
| expect(document.mock!.ownerDocument).not.toEqual(document); | ||
martinsik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| describe('throws an error', () => { | ||
| it('when request method is not JSONP', | ||
| () => expect(() => backend.handle(SAMPLE_REQ.clone<never>({method: 'GET'}))) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this line because the handler should be removed by the handler itself:
angular/packages/common/http/src/jsonp.ts
Line 107 in 2365bb8