Files
DefinitelyTyped/chai-json-schema/chai-json-schema-tests.ts
Ulrich Heiniger 60d039d626 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
2016-12-24 18:57:41 +09:00

57 lines
1.1 KiB
TypeScript

/// <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);