From 1c3380ab16cd81b52c3ad8b50cf97da60ab26066 Mon Sep 17 00:00:00 2001 From: David Broder-Rodgers Date: Mon, 7 Dec 2015 15:11:58 +0000 Subject: [PATCH] Added typings for chai-things --- chai-things/chai-things-tests.ts | 59 ++++++++++++++++++++++++++++++++ chai-things/chai-things.d.ts | 55 +++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 chai-things/chai-things-tests.ts create mode 100644 chai-things/chai-things.d.ts diff --git a/chai-things/chai-things-tests.ts b/chai-things/chai-things-tests.ts new file mode 100644 index 000000000..de6a4c3ff --- /dev/null +++ b/chai-things/chai-things-tests.ts @@ -0,0 +1,59 @@ +/// + +import chai = require('chai'); +import chaiThings = require('chai-things'); + +chai.use(chaiThings); + +function test_somethingSyntax() { + [].should.not.include.something(); + [].should.not.include.something.that.equals(1); + + var array = [{ a: 1 }, { b: 2 }]; + array.should.include.something(); + array.should.include.something.that.deep.equals({ b: 2 }); + array.should.include.something.that.not.deep.equals({ b: 2 }); + array.should.not.include.something.that.deep.equals({ c: 3 }); + array.should.include.something.that.not.deep.equals({ c: 3 }); + array.should.include.something.with.property('b', 2); + array.should.not.include.something.with.property('b', 3); + + var array2 = [{ a: 'b' }, { a: 'b' }]; + array2.should.include.something.that.have.property("a"); + array2.should.include.something.that.have.property("a").not.equal("d"); +} + +function test_somethingVariantsSyntax() { + [].should.not.include.any(); + [].should.not.include.any.that.deep.equal({ b: 2 }); + + var array = [{ a: 1 }, { b: 2 }]; + array.should.include.a.thing(); + array.should.include.a.thing.that.deep.equals({ b: 2 }); + array.should.include.an.item(); + array.should.include.an.item.that.deep.equals({ b: 2 }); + array.should.include.one.that.deep.equals({ b: 2 }); + array.should.include.some(); + array.should.include.some.that.deep.equal({ b: 2 }); +} + +function test_allSyntax() { + [].should.all.equal(1); + [].should.all.not.equal(1); + + var array = [1, 1]; + array.should.all.equal(1); + array.should.all.not.equal(2); + array.should.not.all.equal(2); + array.should.not.all.not.equal(1); + + var array2 = [1, 2]; + array2.should.not.all.equal(1); + array2.should.not.all.equal(2); + array2.should.not.all.not.equal(1); + array2.should.not.all.not.equal(2); + + var array3 = [{ a: 'b' }, { a: 'c' }]; + array3.should.all.have.property("a"); + array3.should.all.have.property("a").not.equal("d"); +} \ No newline at end of file diff --git a/chai-things/chai-things.d.ts b/chai-things/chai-things.d.ts new file mode 100644 index 000000000..bc2b89c46 --- /dev/null +++ b/chai-things/chai-things.d.ts @@ -0,0 +1,55 @@ +// Type definitions for chai-things +// Project: https://github.com/chaijs/chai-things +// Definitions by: David Broder-Rodgers +// Definitions: https://github.com/DavidBR-SW/DefinitelyTyped + +/// + +declare module Chai { + interface ArrayAssertion { + include: ArrayInclude; + contain: ArrayInclude; + not: ArrayAssertion; + all: Assertion; + } + + interface ArrayInclude { + (item: any): any; + a: Item; + an: Item; + one: Something; + some: Something; + something: Something; + any: Anything; + } + + interface Anything extends Assertion { + (): any; + that: Assertion + with: Assertion + } + + interface Something extends Assertion { + (): any; + that: Assertion + with: Assertion + } + + interface Item { + item: Something; + thing: Something; + } + + interface Deep { + equals: Equal; + } +} + +interface Array { + should: Chai.ArrayAssertion; +} + +declare module "chai-things" { + function chaiThings(chai: any, utils: any): void; + export = chaiThings; +}