Merge pull request #21868 from 43081j/sinon-fakeserver

sinon: add fake server options
This commit is contained in:
Bowden Kelly
2017-12-06 10:58:06 -08:00
committed by GitHub
2 changed files with 22 additions and 11 deletions
+12 -11
View File
@@ -1,4 +1,4 @@
// Type definitions for Sinon 4.0
// Type definitions for Sinon 4.1
// Project: http://sinonjs.org/
// Definitions by: William Sears <https://github.com/mrbigdog2u>
// Jonathan Little <https://github.com/rationull>
@@ -11,10 +11,8 @@
// sinon uses DOM dependencies which are absent in browser-less environment like node.js
// to avoid compiler errors this monkey patch is used
// see more details in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11351
// tslint:disable no-empty-interface
interface Event { }
interface Document { }
// tslint:enable no-empty-interface
interface Event { } // tslint:disable-line no-empty-interface
interface Document { } // tslint:disable-line no-empty-interface
declare namespace Sinon {
interface SinonSpyCallApi {
@@ -293,14 +291,10 @@ declare namespace Sinon {
FakeXMLHttpRequest: SinonFakeXMLHttpRequest;
}
interface SinonFakeServer {
interface SinonFakeServer extends SinonFakeServerOptions {
// Properties
autoRespond: boolean;
autoRespondAfter: number;
fakeHTTPMethods: boolean;
getHTTPMethod(request: SinonFakeXMLHttpRequest): string;
requests: SinonFakeXMLHttpRequest[];
respondImmediately: boolean;
// Methods
respondWith(body: string): void;
@@ -322,8 +316,15 @@ declare namespace Sinon {
restore(): void;
}
interface SinonFakeServerOptions {
autoRespond?: boolean;
autoRespondAfter?: number;
fakeHTTPMethods?: boolean;
respondImmediately?: boolean;
}
interface SinonFakeServerStatic {
create(): SinonFakeServer;
create(options?: SinonFakeServerOptions): SinonFakeServer;
}
interface SinonStatic {
+10
View File
@@ -230,6 +230,15 @@ function testSpy() {
sinon.spy().calledImmediatelyBefore(otherSpy);
}
function testFakeServer() {
sinon.fakeServer.create({
autoRespond: true,
autoRespondAfter: 3,
fakeHTTPMethods: true,
respondImmediately: false
});
}
testOne();
testTwo();
testThree();
@@ -249,6 +258,7 @@ testGetterStub();
testSetterStub();
testValueStub();
testThrowsStub();
testFakeServer();
const clock = sinon.useFakeTimers();
clock.setSystemTime(1000);