Included Test for Chai and renamed files to follow the project convention.

This commit is contained in:
Kazi Manzur Rashid
2013-04-30 12:56:41 +06:00
parent fe8140afe8
commit 5362cb55c3
4 changed files with 99 additions and 4 deletions

90
chai/chai-tests.ts Normal file
View File

@@ -0,0 +1,90 @@
/// <reference path="chai.d.ts" />
var expect = chai.expect;
function test_be() {
expect(true).to.be.ok;
expect(true).to.be.true;
expect(false).to.be.false;
expect(null).to.be.null;
expect(undefined).to.be.undefined;
expect([]).to.be.empty;
expect([]).to.be.arguments;
expect({}).to.be.an('object');
expect({}).to.be.an.instanceof(Object);
expect(5).to.be.at.least(5);
expect(5).to.be.at.gte(5);
expect(5).to.be.at.most(5);
expect(5).to.be.at.lte(5);
expect('').to.be.a('string');
expect(5).to.be.within(1, 6);
expect(5.001).to.be.closeTo(5, 0.5);
}
function test_not() {
expect(5).to.not.be.a('string');
}
function test_deep() {
expect(5).to.deep.equal(5);
expect({ foo: 'bar' }).to.deep.property('foo', 'bar');
}
function test_have() {
expect({ foo: 'bar' }).to.have.property('foo', 'bar');
expect([]).to.have.length(5);
expect({ foo: 'bar' }).to.have.ownProperty('foo');
expect('foo-bar').to.have.string('bar');
expect({ foo: 'bar', baz: 'qux' }).to.have.keys('foo', 'baz');
}
function test_exist() {
var obj = { foo: 'bar' };
expect(obj.foo).to.exist;
}
function test_equal() {
expect(5).to.equal(5);
}
function test_include() {
expect('foo-bar').to.include('o-b');
expect([1,2,3]).to.include(2);
expect({ foo: 'bar', baz: 'qux' }).to.include.keys('foo', 'baz');
expect('foo-bar').to.contain('o-b');
expect([1,2,3]).to.contain(2);
expect({ foo: 'bar', baz: 'qux' }).to.contain.keys('foo', 'baz');
}
function test_throw() {
var foo = {
bar: () => { }
};
expect(foo.bar).to.throw(new Error);
expect(foo.bar).to.throw('An error');
expect(foo.bar).to.throw(/error/);
}
function test_eql() {
var foo = {}
expect(foo).to.eql({});
expect(foo).to.eqls({});
}
function test_match() {
expect('foo-bar').to.match(/foo/);
}
function test_respondTo() {
var foo = {
bar: () => { }
};
expect(foo).to.respondTo('bar');
}
function test_satisfy() {
expect(1).to.satisfy((n) => n > 0);
}

View File

@@ -1,4 +1,9 @@
declare module chai {
// Type definitions for chai 1.5.0
// Project: http://chaijs.com/
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
declare module chai {
interface Equality {
(expected: any, message?: string): bool;
}

View File

@@ -1,5 +1,5 @@
/// <reference path="../chai/chai.expect.d.ts" />
/// <reference path="sinon-chai.expect.d.ts" />
/// <reference path="../chai/chai.d.ts" />
/// <reference path="sinon-chai.d.ts" />
var expect = chai.expect;

View File

@@ -3,7 +3,7 @@
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../chai/chai.expect.d.ts" />
/// <reference path="../chai/chai.d.ts" />
declare module chai {
interface Been {