@ -1,24 +1,7 @@
|
||||
import {
|
||||
AsyncTestCompleter,
|
||||
afterEach,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
SpyObject
|
||||
} from 'angular2/testing_internal';
|
||||
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit, SpyObject} from 'angular2/testing_internal';
|
||||
import {ObservableWrapper} from 'angular2/src/facade/async';
|
||||
import {BrowserJsonp} from 'angular2/src/http/backends/browser_jsonp';
|
||||
import {
|
||||
JSONPConnection,
|
||||
JSONPConnection_,
|
||||
JSONPBackend,
|
||||
JSONPBackend_
|
||||
} from 'angular2/src/http/backends/jsonp_backend';
|
||||
import {JSONPConnection, JSONPConnection_, JSONPBackend, JSONPBackend_} from 'angular2/src/http/backends/jsonp_backend';
|
||||
import {provide, Injector} from 'angular2/core';
|
||||
import {isPresent, StringWrapper} from 'angular2/src/facade/lang';
|
||||
import {TimerWrapper} from 'angular2/src/facade/async';
|
||||
@ -93,8 +76,9 @@ export function main() {
|
||||
describe('JSONPConnection', () => {
|
||||
it('should use the injected BaseResponseOptions to create the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
let connection = new JSONPConnection_(sampleRequest, new MockBrowserJsonp(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
let connection = new JSONPConnection_(
|
||||
sampleRequest, new MockBrowserJsonp(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe(res => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
async.done();
|
||||
@ -131,7 +115,7 @@ export function main() {
|
||||
let connection = new JSONPConnection_(sampleRequest, new MockBrowserJsonp());
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
expect("response listener called").toBe(false);
|
||||
expect('response listener called').toBe(false);
|
||||
async.done();
|
||||
},
|
||||
err => {
|
||||
@ -148,7 +132,7 @@ export function main() {
|
||||
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
expect("response listener called").toBe(false);
|
||||
expect('response listener called').toBe(false);
|
||||
async.done();
|
||||
},
|
||||
err => {
|
||||
@ -156,7 +140,7 @@ export function main() {
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingScripts[0].dispatchEvent('error', ({message: "Oops!"}));
|
||||
existingScripts[0].dispatchEvent('error', ({message: 'Oops!'}));
|
||||
}));
|
||||
|
||||
it('should throw if request method is not GET', () => {
|
||||
|
@ -1,16 +1,4 @@
|
||||
import {
|
||||
AsyncTestCompleter,
|
||||
afterEach,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
SpyObject
|
||||
} from 'angular2/testing_internal';
|
||||
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit, SpyObject} from 'angular2/testing_internal';
|
||||
import {ObservableWrapper} from 'angular2/src/facade/async';
|
||||
import {BrowserXhr} from 'angular2/src/http/backends/browser_xhr';
|
||||
import {MockConnection, MockBackend} from 'angular2/src/http/backends/mock_backend';
|
||||
@ -108,8 +96,8 @@ export function main() {
|
||||
let responseObservable: ReplaySubject<Response> =
|
||||
backend.createConnection(sampleRequest1).response;
|
||||
responseObservable.subscribe(res => expect(res.text()).toBe('response1'));
|
||||
responseObservable.subscribe(res => expect(res.text()).toBe('response2'), null,
|
||||
async.done);
|
||||
responseObservable.subscribe(
|
||||
res => expect(res.text()).toBe('response2'), null, async.done);
|
||||
}));
|
||||
|
||||
// TODO(robwormald): readyStates are leaving?
|
||||
|
@ -1,16 +1,4 @@
|
||||
import {
|
||||
AsyncTestCompleter,
|
||||
afterEach,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
SpyObject
|
||||
} from 'angular2/testing_internal';
|
||||
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit, SpyObject} from 'angular2/testing_internal';
|
||||
import {ObservableWrapper} from 'angular2/src/facade/async';
|
||||
import {BrowserXhr} from 'angular2/src/http/backends/browser_xhr';
|
||||
import {XHRConnection, XHRBackend} from 'angular2/src/http/backends/xhr_backend';
|
||||
@ -88,8 +76,7 @@ export function main() {
|
||||
beforeEach(() => {
|
||||
var injector = Injector.resolveAndCreate([
|
||||
provide(ResponseOptions, {useClass: BaseResponseOptions}),
|
||||
provide(BrowserXhr, {useClass: MockBrowserXHR}),
|
||||
XHRBackend
|
||||
provide(BrowserXhr, {useClass: MockBrowserXHR}), XHRBackend
|
||||
]);
|
||||
backend = injector.get(XHRBackend);
|
||||
var base = new BaseRequestOptions();
|
||||
@ -105,8 +92,9 @@ export function main() {
|
||||
describe('XHRConnection', () => {
|
||||
it('should use the injected BaseResponseOptions to create the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
async.done();
|
||||
@ -116,11 +104,12 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should complete a request', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
}, null, () => { async.done(); });
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe(
|
||||
(res: Response) => { expect(res.type).toBe(ResponseType.Error); }, null,
|
||||
() => { async.done(); });
|
||||
existingXHRs[0].setStatusCode(200);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
@ -134,8 +123,9 @@ export function main() {
|
||||
|
||||
it('should create an error Response on error',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe(null, (res: Response) => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
async.done();
|
||||
@ -177,8 +167,8 @@ export function main() {
|
||||
it('should return the correct status code',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 418;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(
|
||||
(res: Response) => {
|
||||
@ -198,15 +188,16 @@ export function main() {
|
||||
var nextCalled = false;
|
||||
var errorCalled = false;
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(
|
||||
(res: Response) => {
|
||||
nextCalled = true;
|
||||
expect(res.status).toBe(statusCode);
|
||||
},
|
||||
errRes => { errorCalled = true; }, () => {
|
||||
errRes => { errorCalled = true; },
|
||||
() => {
|
||||
expect(nextCalled).toBe(true);
|
||||
expect(errorCalled).toBe(false);
|
||||
async.done();
|
||||
@ -221,14 +212,17 @@ export function main() {
|
||||
var nextCalled = false;
|
||||
var errorCalled = false;
|
||||
var statusCode = 301;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe((res: Response) => { nextCalled = true; }, errRes => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
expect(nextCalled).toBe(false);
|
||||
async.done();
|
||||
}, () => { throw 'should not be called'; });
|
||||
connection.response.subscribe(
|
||||
(res: Response) => { nextCalled = true; },
|
||||
errRes => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
expect(nextCalled).toBe(false);
|
||||
async.done();
|
||||
},
|
||||
() => { throw 'should not be called'; });
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
@ -237,8 +231,8 @@ export function main() {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 1223;
|
||||
var normalizedCode = 204;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.status).toBe(normalizedCode);
|
||||
@ -278,8 +272,8 @@ export function main() {
|
||||
it('should parse response headers and add them to the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
let responseHeaderString =
|
||||
`Date: Fri, 20 Nov 2015 01:45:26 GMT
|
||||
@ -303,8 +297,8 @@ export function main() {
|
||||
it('should add the responseURL to the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.url).toEqual('http://google.com');
|
||||
@ -319,8 +313,8 @@ export function main() {
|
||||
it('should add use the X-Request-URL in CORS situations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
var responseHeaders = `X-Request-URL: http://somedomain.com
|
||||
Foo: Bar`
|
||||
|
||||
|
@ -1,14 +1,4 @@
|
||||
import {
|
||||
AsyncTestCompleter,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from 'angular2/testing_internal';
|
||||
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from 'angular2/testing_internal';
|
||||
import {BaseRequestOptions, RequestOptions} from 'angular2/src/http/base_request_options';
|
||||
import {RequestMethod} from 'angular2/src/http/enums';
|
||||
|
||||
|
@ -1,17 +1,7 @@
|
||||
import {Headers} from 'angular2/src/http/headers';
|
||||
import {Json} from 'angular2/src/facade/lang';
|
||||
import {Map, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
import {
|
||||
AsyncTestCompleter,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from 'angular2/testing_internal';
|
||||
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from 'angular2/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('Headers', () => {
|
||||
|
@ -1,33 +1,7 @@
|
||||
import {
|
||||
AsyncTestCompleter,
|
||||
afterEach,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from 'angular2/testing_internal';
|
||||
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from 'angular2/testing_internal';
|
||||
import {Injector, provide} from 'angular2/core';
|
||||
import {MockBackend, MockConnection} from 'angular2/src/http/backends/mock_backend';
|
||||
import {
|
||||
BaseRequestOptions,
|
||||
ConnectionBackend,
|
||||
Request,
|
||||
RequestMethod,
|
||||
RequestOptions,
|
||||
Response,
|
||||
ResponseOptions,
|
||||
URLSearchParams,
|
||||
JSONP_PROVIDERS,
|
||||
HTTP_PROVIDERS,
|
||||
XHRBackend,
|
||||
JSONPBackend,
|
||||
Http,
|
||||
Jsonp
|
||||
} from 'angular2/http';
|
||||
import {BaseRequestOptions, ConnectionBackend, Request, RequestMethod, RequestOptions, Response, ResponseOptions, URLSearchParams, JSONP_PROVIDERS, HTTP_PROVIDERS, XHRBackend, JSONPBackend, Http, Jsonp} from 'angular2/http';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Subject} from 'rxjs/Subject';
|
||||
|
||||
@ -49,9 +23,7 @@ export function main() {
|
||||
]);
|
||||
|
||||
childInjector = parentInjector.resolveAndCreateChild([
|
||||
HTTP_PROVIDERS,
|
||||
JSONP_PROVIDERS,
|
||||
provide(XHRBackend, {useClass: MockBackend}),
|
||||
HTTP_PROVIDERS, JSONP_PROVIDERS, provide(XHRBackend, {useClass: MockBackend}),
|
||||
provide(JSONPBackend, {useClass: MockBackend})
|
||||
]);
|
||||
|
||||
@ -95,24 +67,18 @@ export function main() {
|
||||
var jsonp: Jsonp;
|
||||
beforeEach(() => {
|
||||
injector = Injector.resolveAndCreate([
|
||||
BaseRequestOptions,
|
||||
MockBackend,
|
||||
provide(
|
||||
Http,
|
||||
{
|
||||
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||
return new Http(backend, defaultOptions);
|
||||
},
|
||||
deps: [MockBackend, BaseRequestOptions]
|
||||
}),
|
||||
provide(
|
||||
Jsonp,
|
||||
{
|
||||
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||
return new Jsonp(backend, defaultOptions);
|
||||
},
|
||||
deps: [MockBackend, BaseRequestOptions]
|
||||
})
|
||||
BaseRequestOptions, MockBackend, provide(Http, {
|
||||
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||
return new Http(backend, defaultOptions);
|
||||
},
|
||||
deps: [MockBackend, BaseRequestOptions]
|
||||
}),
|
||||
provide(Jsonp, {
|
||||
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||
return new Jsonp(backend, defaultOptions);
|
||||
},
|
||||
deps: [MockBackend, BaseRequestOptions]
|
||||
})
|
||||
]);
|
||||
http = injector.get(Http);
|
||||
jsonp = injector.get(Jsonp);
|
||||
@ -156,11 +122,10 @@ export function main() {
|
||||
it('should perform a get request for given url if only passed a string',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
http.request('http://basic.connection').subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a post request for given url if options include a method',
|
||||
@ -170,11 +135,10 @@ export function main() {
|
||||
c.mockRespond(baseResponse);
|
||||
});
|
||||
let requestOptions = new RequestOptions({method: RequestMethod.Post});
|
||||
http.request('http://basic.connection', requestOptions)
|
||||
.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
http.request('http://basic.connection', requestOptions).subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a post request for given url if options include a method',
|
||||
@ -184,30 +148,32 @@ export function main() {
|
||||
c.mockRespond(baseResponse);
|
||||
});
|
||||
let requestOptions = {method: RequestMethod.Post};
|
||||
http.request('http://basic.connection', requestOptions)
|
||||
.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
http.request('http://basic.connection', requestOptions).subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a get request and complete the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
.subscribe(
|
||||
(res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
}));
|
||||
|
||||
it('should perform multiple get requests and complete the responses',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
||||
|
||||
http.request('http://basic.connection').subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
});
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => { expect(res.text()).toBe('base response'); });
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
.subscribe(
|
||||
(res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
}));
|
||||
|
||||
it('should throw if url is not a string or Request', () => {
|
||||
@ -373,9 +339,8 @@ export function main() {
|
||||
it('should allow case insensitive strings for method names', () => {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => {
|
||||
expect(c.request.method)
|
||||
.toBe(RequestMethod.Post)
|
||||
c.mockRespond(new Response(new ResponseOptions({body: 'Thank you'})));
|
||||
expect(c.request.method).toBe(RequestMethod.Post)
|
||||
c.mockRespond(new Response(new ResponseOptions({body: 'Thank you'})));
|
||||
async.done();
|
||||
});
|
||||
http.request(
|
||||
|
@ -1,38 +1,28 @@
|
||||
import {
|
||||
AsyncTestCompleter,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from 'angular2/testing_internal';
|
||||
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from 'angular2/testing_internal';
|
||||
import {URLSearchParams} from 'angular2/src/http/url_search_params';
|
||||
|
||||
export function main() {
|
||||
describe('URLSearchParams', () => {
|
||||
it('should conform to spec', () => {
|
||||
var paramsString = "q=URLUtils.searchParams&topic=api";
|
||||
var paramsString = 'q=URLUtils.searchParams&topic=api';
|
||||
var searchParams = new URLSearchParams(paramsString);
|
||||
|
||||
// Tests borrowed from example at
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
|
||||
// Compliant with spec described at https://url.spec.whatwg.org/#urlsearchparams
|
||||
expect(searchParams.has("topic")).toBe(true);
|
||||
expect(searchParams.has("foo")).toBe(false);
|
||||
expect(searchParams.get("topic")).toEqual("api");
|
||||
expect(searchParams.getAll("topic")).toEqual(["api"]);
|
||||
expect(searchParams.get("foo")).toBe(null);
|
||||
searchParams.append("topic", "webdev");
|
||||
expect(searchParams.getAll("topic")).toEqual(["api", "webdev"]);
|
||||
expect(searchParams.toString()).toEqual("q=URLUtils.searchParams&topic=api&topic=webdev");
|
||||
searchParams.delete("topic");
|
||||
expect(searchParams.toString()).toEqual("q=URLUtils.searchParams");
|
||||
expect(searchParams.has('topic')).toBe(true);
|
||||
expect(searchParams.has('foo')).toBe(false);
|
||||
expect(searchParams.get('topic')).toEqual('api');
|
||||
expect(searchParams.getAll('topic')).toEqual(['api']);
|
||||
expect(searchParams.get('foo')).toBe(null);
|
||||
searchParams.append('topic', 'webdev');
|
||||
expect(searchParams.getAll('topic')).toEqual(['api', 'webdev']);
|
||||
expect(searchParams.toString()).toEqual('q=URLUtils.searchParams&topic=api&topic=webdev');
|
||||
searchParams.delete('topic');
|
||||
expect(searchParams.toString()).toEqual('q=URLUtils.searchParams');
|
||||
|
||||
// Test default constructor
|
||||
expect(new URLSearchParams().toString()).toBe("");
|
||||
expect(new URLSearchParams().toString()).toBe('');
|
||||
});
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user