diff --git a/types/jasmine-ajax/index.d.ts b/types/jasmine-ajax/index.d.ts index 1386a7b8a2..3032f8f515 100644 --- a/types/jasmine-ajax/index.d.ts +++ b/types/jasmine-ajax/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for jasmine-ajax 3.1 +// Type definitions for jasmine-ajax 3.3 // Project: https://github.com/jasmine/jasmine-ajax // Definitions by: Louis Grignon +// Julian Gonggrijp // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -25,7 +26,7 @@ interface JasmineAjaxRequest extends XMLHttpRequest { respondWith(response: JasmineAjaxResponse): void; responseTimeout(): void; - responseError(): void; + responseError(options?: JasmineAjaxRequestStubErrorOptions): void; } interface JasmineAjaxRequestTracker { @@ -36,7 +37,7 @@ interface JasmineAjaxRequestTracker { mostRecent(): JasmineAjaxRequest; at(index: number): JasmineAjaxRequest; filter(urlToMatch: RegExp): JasmineAjaxRequest[]; - filter(urlToMatch: Function): JasmineAjaxRequest[]; + filter(urlToMatch: (request: JasmineAjaxRequest) => boolean): JasmineAjaxRequest[]; filter(urlToMatch: string): JasmineAjaxRequest[]; } @@ -48,10 +49,20 @@ interface JasmineAjaxRequestStubReturnOptions { responseHeaders?: { [key: string]: string }; } +interface JasmineAjaxRequestStubErrorOptions { + status?: number; + statusText?: string; +} + interface JasmineAjaxRequestStub { - data?: string; - method?: string; + url: RegExp | string; + query: string; + data: string; + method: string; andReturn(options: JasmineAjaxRequestStubReturnOptions): void; + andError(options: JasmineAjaxRequestStubErrorOptions): void; + andTimeout(): void; + andCallFunction(functionToCall: (request: JasmineAjaxRequest) => void): void; matches(fullUrl: string, data: string, method: string): boolean; } diff --git a/types/jasmine-ajax/jasmine-ajax-tests.ts b/types/jasmine-ajax/jasmine-ajax-tests.ts index a40a9f6e42..669f29c5e0 100644 --- a/types/jasmine-ajax/jasmine-ajax-tests.ts +++ b/types/jasmine-ajax/jasmine-ajax-tests.ts @@ -1431,6 +1431,42 @@ describe('RequestStub', () => { expect(stub)['toMatchRequest']('/foo', 'baz=quux&foo=bar'); expect(stub).not['toMatchRequest']('/foo', 'foo=bar'); }); + + it('has methods', () => { + jasmine.Ajax.stubRequest('/foo').andReturn({ + status: 200, + contentType: 'application/json', + responseText: '{"success": true}', + responseHeaders: { 'X-Example': 'a value' }, + }); + jasmine.Ajax.stubRequest('/bar').andReturn({}); + jasmine.Ajax.stubRequest('/baz').andError({ + status: 400, + statusText: 'Invalid', + }); + jasmine.Ajax.stubRequest('/foobar').andError({}); + jasmine.Ajax.stubRequest('/foobaz').andTimeout(); + jasmine.Ajax.stubRequest('/barbaz').andCallFunction((xhr) => { + xhr.url === '/barbaz'; + xhr.method === 'POST'; + xhr.params === {}; + xhr.username === 'jane_coder'; + xhr.password === '12345'; + xhr.requestHeaders === {Accept: 'application/json'}; + xhr.data() === {query: 'bananas'}; + xhr.respondWith({ + status: 200, + contentType: 'application/json', + responseText: '{"success": true}', + responseHeaders: { 'X-Example': 'a value' }, + }); + xhr.responseTimeout(); + xhr.responseError({ + status: 400, + statusText: 'Invalid', + }); + }); + }); }); describe('RequestTracker', () => { diff --git a/types/jasmine-ajax/tslint.json b/types/jasmine-ajax/tslint.json index 1b62a88e52..08b1465cd6 100644 --- a/types/jasmine-ajax/tslint.json +++ b/types/jasmine-ajax/tslint.json @@ -1,7 +1,6 @@ { "extends": "dtslint/dt.json", "rules": { - "ban-types": false, "unified-signatures": false } }