From 60d039d626c4ff8ee72b15fb751acd5bbe485a83 Mon Sep 17 00:00:00 2001 From: Ulrich Heiniger Date: Sat, 24 Dec 2016 10:57:41 +0100 Subject: [PATCH] Add type definitions for chai-json-schema (#13036) * Add type definitions for chai-json-schema * Change to types-2.0 style * Change reference path * Fix namespace name * Fix should example in tests --- chai-json-schema/chai-json-schema-tests.ts | 56 ++++++++++++++++++++++ chai-json-schema/index.d.ts | 24 ++++++++++ chai-json-schema/tsconfig.json | 19 ++++++++ chai-json-schema/tslint.json | 5 ++ 4 files changed, 104 insertions(+) create mode 100644 chai-json-schema/chai-json-schema-tests.ts create mode 100644 chai-json-schema/index.d.ts create mode 100644 chai-json-schema/tsconfig.json create mode 100644 chai-json-schema/tslint.json diff --git a/chai-json-schema/chai-json-schema-tests.ts b/chai-json-schema/chai-json-schema-tests.ts new file mode 100644 index 0000000000..8559d3caae --- /dev/null +++ b/chai-json-schema/chai-json-schema-tests.ts @@ -0,0 +1,56 @@ +/// + +import { expect } from 'chai'; +import { assert } from 'chai'; + +import chai = require('chai'); +import ChaiJsonSchema = require('chai-json-schema'); + +chai.use(ChaiJsonSchema); +chai.should(); + +let goodApple = { + skin: 'thin', + colors: ['red', 'green', 'yellow'], + taste: 10 +}; + +let badApple = { + colors: ['brown'], + taste: 0, + worms: 2 +}; + +let fruitSchema = { + title: 'fresh fruit schema v1', + type: 'object', + required: ['skin', 'colors', 'taste'], + properties: { + colors: { + type: 'array', + minItems: 1, + uniqueItems: true, + items: { + type: 'string' + } + }, + skin: { + type: 'string' + }, + taste: { + type: 'number', + minimum: 5 + } + } +}; + +//bdd style +expect(goodApple).to.be.jsonSchema(fruitSchema); +expect(badApple).to.not.be.jsonSchema(fruitSchema); + +goodApple.should.be.jsonSchema(fruitSchema); +badApple.should.not.be.jsonSchema(fruitSchema); + +//tdd style +assert.jsonSchema(goodApple, fruitSchema); +assert.notJsonSchema(badApple, fruitSchema); diff --git a/chai-json-schema/index.d.ts b/chai-json-schema/index.d.ts new file mode 100644 index 0000000000..e3e4934c76 --- /dev/null +++ b/chai-json-schema/index.d.ts @@ -0,0 +1,24 @@ +// Type definitions for chai-json-schema 1.4 +// Project: https://github.com/chaijs/chai-json-schema/ +// Definitions by: Ulrich Heiniger +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// +// + +declare namespace Chai { + export interface Assert { + jsonSchema(value: any, schema: any, msg?: string): void; + notJsonSchema(value: any, schema: any, msg?: string): void; + } + + export interface LanguageChains { + jsonSchema(schema: any, msg?: string): void; + } +} + +declare module "chai-json-schema" { + function chaiJsonSchema(chai: any, utils: any): void; + namespace chaiJsonSchema {} + export = chaiJsonSchema; +} diff --git a/chai-json-schema/tsconfig.json b/chai-json-schema/tsconfig.json new file mode 100644 index 0000000000..1ac8b87c7a --- /dev/null +++ b/chai-json-schema/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "chai-json-schema-tests.ts" + ] +} diff --git a/chai-json-schema/tslint.json b/chai-json-schema/tslint.json new file mode 100644 index 0000000000..83a03ce890 --- /dev/null +++ b/chai-json-schema/tslint.json @@ -0,0 +1,5 @@ +{ "extends": "../tslint.json", + "rules": { + "no-single-declare-module": false + } +}