diff --git a/types/frisby/frisby-tests.ts b/types/frisby/frisby-tests.ts new file mode 100644 index 0000000000..801ea63be7 --- /dev/null +++ b/types/frisby/frisby-tests.ts @@ -0,0 +1,38 @@ +//Example from https://www.npmjs.com/package/frisby + +import frisby = require('frisby'); + +var URL = 'http://localhost:3000/'; +var URL_AUTH = 'http://username:password@localhost:3000/'; + +frisby.globalSetup({ // globalSetup is for ALL requests + request: { + headers: { 'X-Auth-Token': 'fa8426a0-8eaf-4d22-8e13-7c1b16a9370c' } + } +}); + +frisby.create('GET user johndoe') + .get(URL + '/users/3.json') + .expectStatus(200) + .expectJSONTypes({ + id: Number, + username: String, + is_admin: Boolean + }) + .expectJSON({ + id: 3, + username: 'johndoe', + is_admin: false + }) + // 'afterJSON' automatically parses response body as JSON and passes it as an argument + .afterJSON(function(user) { + // You can use any normal jasmine-style assertions here + expect(1+1).toEqual(2); + + // Use data from previous result in next test + frisby.create('Update user') + .put(URL_AUTH + '/users/' + user.id + '.json', {tags: ['jasmine', 'bdd']}) + .expectStatus(200) + .toss(); + }) +.toss(); \ No newline at end of file diff --git a/types/frisby/index.d.ts b/types/frisby/index.d.ts new file mode 100644 index 0000000000..b607574b7e --- /dev/null +++ b/types/frisby/index.d.ts @@ -0,0 +1,73 @@ +// Type definitions for Frisby v0.8.5 +// Project: https://github.com/vlucas/frisby +// Definitions by: Johnny Li +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare interface Frisby { + globalSetup(opts: any): any; + timeout(seconds?: number): Frisby; + reset(): Frisby; + not(): Frisby; + addHeader(key: string, content: string): Frisby; + addHeaders(headers: object): Frisby; + removeHeader(key: string): Frisby; + responseType(type: any): Frisby; + // HTTP Basic Auth + auth(username: string, password: string, digest: boolean): Frisby; + // HTTP Request + get(uri: string, params?: any): Frisby; + patch(uri: string, data?: any, params?: any): Frisby; + post(uri: string, data?: any, params?: any): Frisby; + put(uri: string, data?: any, params?: any): Frisby; + delete(uri: string, data?: any, params?: any): Frisby; + head(uri: string, params?: any): Frisby; + options(uri: string, params?: any): Frisby; + + expectMaxResponseTime(milliseconds: number): Frisby; + expectStatus(statusCode: number): Frisby; + expectHeader(header: string, content: string): Frisby; + expectHeaderContains(header: string, content: string): Frisby; + expectHeaderToMatch(header: string, pattern: RegExp): Frisby; + expectBodyContains(content: string): Frisby; + expectJSONTypes(json: any): Frisby; + expectJSONTypes(path: string, json: any): Frisby; + expectJSON(json: any): Frisby; + expectJSON(path: string, json: any): Frisby; + expectJSONSchema(path: string, jsonSchema: any): Frisby; + expectJSONLength(length: number): Frisby; + expectJSONLength(path: string, length: number): Frisby; + inspectRequest(): Frisby; + inspectResponse(): Frisby; + inspectHeaders(): Frisby; + inspectBody(): Frisby; + inspectJSON(): Frisby; + inspectStatus(): Frisby; + retry(count: number, delayInMilliseconds?: number): Frisby; + waits(delayInMilliseconds: number): Frisby; + after(callback: (...args: any[]) => void): Frisby; + afterJSON(callback: (...args: any[]) => void): Frisby; + exceptionHandler(fn: (...args: any[]) => void): Frisby; + toss(): void; + + create(msg: string): Frisby; + +} + +declare namespace jasmine { + interface Matchers { + toMatchOrBeNull(expected: any): boolean; + toMatchOrBeEmpty(expected: any): boolean; + toBeType(expected: any): boolean; + toBeTypeOrNull(expected: any): boolean; + toBeTypeOrUndefined(expected: any): boolean; + toContainJson(expected: any, isNot?: boolean): boolean; + toContainJsonTypes(expected: any, isNot?: boolean): boolean; + } +} + +declare const frisby: Frisby; +declare module "frisby" { + export = frisby; +} diff --git a/types/frisby/tsconfig.json b/types/frisby/tsconfig.json new file mode 100644 index 0000000000..5ff4c5d7f1 --- /dev/null +++ b/types/frisby/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "frisby-tests.ts" + ] +} \ No newline at end of file