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
This commit is contained in:
Ulrich Heiniger
2016-12-24 18:57:41 +09:00
committed by Masahiro Wakame
parent c32938577f
commit 60d039d626
4 changed files with 104 additions and 0 deletions
@@ -0,0 +1,56 @@
/// <reference path="index.d.ts" />
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);
+24
View File
@@ -0,0 +1,24 @@
// Type definitions for chai-json-schema 1.4
// Project: https://github.com/chaijs/chai-json-schema/
// Definitions by: Ulrich Heiniger <https://github.com/ulrichheiniger>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// <reference types="node"/>
// <reference types="chai" />
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;
}
+19
View File
@@ -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"
]
}
+5
View File
@@ -0,0 +1,5 @@
{ "extends": "../tslint.json",
"rules": {
"no-single-declare-module": false
}
}