From 21290fe29e85c53aad7f9dbd1d47a2cf8a360311 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 5 Apr 2017 18:52:03 -0700 Subject: [PATCH 1/3] Docs and some missing functions for chai.assert Bumped Chai version to 3.5.0. --- types/chai/chai-tests.ts | 1388 ++++++++++++++------------------------ types/chai/index.d.ts | 1029 +++++++++++++++++++++++++--- 2 files changed, 1431 insertions(+), 986 deletions(-) diff --git a/types/chai/chai-tests.ts b/types/chai/chai-tests.ts index 7f104d07e5..756212995d 100644 --- a/types/chai/chai-tests.ts +++ b/types/chai/chai-tests.ts @@ -1,16 +1,11 @@ +import * as chai from "chai"; -import chai = require('chai'); +const expect = chai.expect; +const assert = chai.assert; +const should = chai.should(); -// ReSharper disable WrongExpressionStatement - -var expect = chai.expect; -var assert = chai.assert; -var should = chai.should(); -declare var err: Function; - -function chaiVersion() { - expect(chai).to.have.property('version'); - (<{}>chai).should.have.property('version'); +function chaiVersion(): string { + return chai.version; } function assertion() { @@ -22,28 +17,13 @@ function assertion() { } function fail() { - err(() => { - should.fail('foo', 'bar'); - }, 'expected fail to throw an AssertionError'); - err(() => { - should.fail('foo', 'bar', 'should fail'); - }, 'expected fail to throw an AssertionError'); - err(() => { - should.fail('foo', 'bar', 'should fail', 'equal'); - }, 'expected fail to throw an AssertionError'); + should.fail('foo', 'bar'); + should.fail('foo', 'bar', 'should fail'); - err(() => { - expect.fail('foo', 'bar'); - }, 'expected fail to throw an AssertionError'); - err(() => { - expect.fail('foo', 'bar', 'should fail'); - }, 'expected fail to throw an AssertionError'); - err(() => { - expect.fail('foo', 'bar', 'should fail', 'equal'); - }, 'expected fail to throw an AssertionError'); + expect.fail('foo', 'bar'); + expect.fail('foo', 'bar', 'should fail'); } -// ReSharper disable once InconsistentNaming function _true() { expect(true).to.be.true; true.should.be.true; @@ -52,10 +32,8 @@ function _true() { expect(1).to.not.be.true; (1).should.not.be.true; - err(() => { - expect('test').to.be.true; - 'test'.should.be.true; - }, 'expected \'test\' to be true'); + expect('test').to.be.true; + 'test'.should.be.true; } function ok() { @@ -68,15 +46,11 @@ function ok() { expect(0).to.not.be.ok; (0).should.not.be.ok; - err(() => { - expect('').to.be.ok; - ''.should.be.ok; - }, 'expected \'\' to be truthy'); + expect('').to.be.ok; + ''.should.be.ok; - err(() => { - expect('test').to.not.be.ok; - 'test'.should.not.be.ok; - }, 'expected \'test\' to be falsy'); + expect('test').to.not.be.ok; + 'test'.should.not.be.ok; } function _false() { @@ -87,10 +61,8 @@ function _false() { expect(0).to.not.be.false; (0).should.not.be.false; - err(() => { - expect('').to.be.false; - ''.should.be.false; - }, 'expected \'\' to be false'); + expect('').to.be.false; + ''.should.be.false; } function _null() { @@ -99,10 +71,8 @@ function _null() { expect(false).to.not.be.null; false.should.not.be.null; - err(() => { - expect('').to.be.null; - ''.should.be.null; - }, 'expected \'\' to be null'); + expect('').to.be.null; + ''.should.be.null; } function _undefined() { @@ -111,10 +81,8 @@ function _undefined() { expect(null).to.not.be.undefined; should.not.equal(null, undefined); - err(() => { - expect('').to.be.undefined; - ''.should.be.undefined; - }, 'expected \'\' to be undefined'); + expect('').to.be.undefined; + ''.should.be.undefined; } function _NaN() { @@ -127,7 +95,7 @@ function _NaN() { } function exist() { - var foo = 'bar'; + const foo = 'bar'; expect(foo).to.exist; should.exist(foo); expect(void (0)).to.not.exist; @@ -135,7 +103,7 @@ function exist() { } function argumentsTest() { - var args = arguments; + const args = arguments; expect(args).to.be.arguments; args.should.be.arguments; expect([]).to.not.be.arguments; @@ -155,10 +123,8 @@ function _typeof() { expect('test').to.be.a('string'); 'test'.should.be.a('string'); - err(() => { - expect('test').to.not.be.a('string'); - 'test'.should.not.be.a('string'); - }, 'expected \'test\' not to be a string'); + expect('test').to.not.be.a('string'); + 'test'.should.not.be.a('string'); expect(arguments).to.be.an('arguments'); arguments.should.be.an('arguments'); @@ -185,10 +151,8 @@ function _typeof() { expect(null).to.be.a('null'); // N.B. previous line has no should equivalent - err(() => { - expect(5).to.not.be.a('number', 'blah'); - (5).should.not.be.a('number', 'blah'); - }, 'blah: expected 5 not to be a number'); + expect(5).to.not.be.a('number', 'blah'); + (5).should.not.be.a('number', 'blah'); } class Foo { } @@ -196,10 +160,8 @@ function _instanceof() { expect(new Foo()).to.be.an.instanceof(Foo); (new Foo()).should.be.an.instanceof(Foo); - err(() => { - expect(3).to.an.instanceof(Foo, 'blah'); - (3).should.an.instanceof(Foo, 'blah'); - }, 'blah: expected 3 to be an instance of Foo'); + expect(3).to.an.instanceof(Foo, 'blah'); + (3).should.an.instanceof(Foo, 'blah'); } function within() { @@ -216,25 +178,17 @@ function within() { expect([1, 2, 3]).to.have.length.within(2, 4); [1, 2, 3].should.have.length.within(2, 4); - err(() => { - expect(5).to.not.be.within(4, 6, 'blah'); - (5).should.not.be.within(4, 6, 'blah'); - }, 'blah: expected 5 to not be within 4..6', 'blah'); + expect(5).to.not.be.within(4, 6, 'blah'); + (5).should.not.be.within(4, 6, 'blah'); - err(() => { - expect(10).to.be.within(50, 100, 'blah'); - (10).should.be.within(50, 100, 'blah'); - }, 'blah: expected 10 to be within 50..100'); + expect(10).to.be.within(50, 100, 'blah'); + (10).should.be.within(50, 100, 'blah'); - err(() => { - expect('foo').to.have.length.within(5, 7, 'blah'); - 'foo'.should.have.length.within(5, 7, 'blah'); - }, 'blah: expected \'foo\' to have a length within 5..7'); + expect('foo').to.have.length.within(5, 7, 'blah'); + 'foo'.should.have.length.within(5, 7, 'blah'); - err(() => { - expect([1, 2, 3]).to.have.length.within(5, 7, 'blah'); - [1, 2, 3].should.have.length.within(5, 7, 'blah'); - }, 'blah: expected [ 1, 2, 3 ] to have a length within 5..7'); + expect([1, 2, 3]).to.have.length.within(5, 7, 'blah'); + [1, 2, 3].should.have.length.within(5, 7, 'blah'); } function above() { @@ -251,25 +205,17 @@ function above() { expect([1, 2, 3]).to.have.length.above(2); [1, 2, 3].should.have.length.above(2); - err(() => { - expect(5).to.be.above(6, 'blah'); - (5).should.be.above(6, 'blah'); - }, 'blah: expected 5 to be above 6', 'blah'); + expect(5).to.be.above(6, 'blah'); + (5).should.be.above(6, 'blah'); - err(() => { - expect(10).to.not.be.above(6, 'blah'); - (10).should.not.be.above(6, 'blah'); - }, 'blah: expected 10 to be at most 6'); + expect(10).to.not.be.above(6, 'blah'); + (10).should.not.be.above(6, 'blah'); - err(() => { - expect('foo').to.have.length.above(4, 'blah'); - 'foo'.should.have.length.above(4, 'blah'); - }, 'blah: expected \'foo\' to have a length above 4 but got 3'); + expect('foo').to.have.length.above(4, 'blah'); + 'foo'.should.have.length.above(4, 'blah'); - err(() => { - expect([1, 2, 3]).to.have.length.above(4, 'blah'); - [1, 2, 3].should.have.length.above(4, 'blah'); - }, 'blah: expected [ 1, 2, 3 ] to have a length above 4 but got 3'); + expect([1, 2, 3]).to.have.length.above(4, 'blah'); + [1, 2, 3].should.have.length.above(4, 'blah'); } function least() { @@ -284,30 +230,20 @@ function least() { expect([1, 2, 3]).to.have.length.of.at.least(2); [1, 2, 3].should.have.length.of.at.least(2); - err(() => { - expect(5).to.be.at.least(6, 'blah'); - (5).should.be.at.least(6, 'blah'); - }, 'blah: expected 5 to be at least 6', 'blah'); + expect(5).to.be.at.least(6, 'blah'); + (5).should.be.at.least(6, 'blah'); - err(() => { - expect(10).to.not.be.at.least(6, 'blah'); - (10).should.not.be.at.least(6, 'blah'); - }, 'blah: expected 10 to be below 6'); + expect(10).to.not.be.at.least(6, 'blah'); + (10).should.not.be.at.least(6, 'blah'); - err(() => { - expect('foo').to.have.length.of.at.least(4, 'blah'); - 'foo'.should.have.length.of.at.least(4, 'blah'); - }, 'blah: expected \'foo\' to have a length at least 4 but got 3'); + expect('foo').to.have.length.of.at.least(4, 'blah'); + 'foo'.should.have.length.of.at.least(4, 'blah'); - err(() => { - expect([1, 2, 3]).to.have.length.of.at.least(4, 'blah'); - [1, 2, 3].should.have.length.of.at.least(4, 'blah'); - }, 'blah: expected [ 1, 2, 3 ] to have a length at least 4 but got 3'); + expect([1, 2, 3]).to.have.length.of.at.least(4, 'blah'); + [1, 2, 3].should.have.length.of.at.least(4, 'blah'); - err(() => { - expect([1, 2, 3, 4]).to.not.have.length.of.at.least(4, 'blah'); - [1, 2, 3, 4].should.not.have.length.of.at.least(4, 'blah'); - }, 'blah: expected [ 1, 2, 3, 4 ] to have a length below 4'); + expect([1, 2, 3, 4]).to.not.have.length.of.at.least(4, 'blah'); + [1, 2, 3, 4].should.not.have.length.of.at.least(4, 'blah'); } function below() { @@ -324,25 +260,17 @@ function below() { expect([1, 2, 3]).to.have.length.below(4); [1, 2, 3].should.have.length.below(4); - err(() => { - expect(6).to.be.below(5, 'blah'); - (6).should.be.below(5, 'blah'); - }, 'blah: expected 6 to be below 5'); + expect(6).to.be.below(5, 'blah'); + (6).should.be.below(5, 'blah'); - err(() => { - expect(6).to.not.be.below(10, 'blah'); - (6).should.not.be.below(10, 'blah'); - }, 'blah: expected 6 to be at least 10'); + expect(6).to.not.be.below(10, 'blah'); + (6).should.not.be.below(10, 'blah'); - err(() => { - expect('foo').to.have.length.below(2, 'blah'); - 'foo'.should.have.length.below(2, 'blah'); - }, 'blah: expected \'foo\' to have a length below 2 but got 3'); + expect('foo').to.have.length.below(2, 'blah'); + 'foo'.should.have.length.below(2, 'blah'); - err(() => { - expect([1, 2, 3]).to.have.length.below(2, 'blah'); - [1, 2, 3].should.have.length.below(2, 'blah'); - }, 'blah: expected [ 1, 2, 3 ] to have a length below 2 but got 3'); + expect([1, 2, 3]).to.have.length.below(2, 'blah'); + [1, 2, 3].should.have.length.below(2, 'blah'); } function most() { @@ -359,30 +287,20 @@ function most() { expect([1, 2, 3]).to.have.length.of.at.most(4); [1, 2, 3].should.have.length.of.at.most(4); - err(() => { - expect(6).to.be.at.most(5, 'blah'); - (6).should.be.at.most(5, 'blah'); - }, 'blah: expected 6 to be at most 5'); + expect(6).to.be.at.most(5, 'blah'); + (6).should.be.at.most(5, 'blah'); - err(() => { - expect(6).to.not.be.at.most(10, 'blah'); - (6).should.not.be.at.most(10, 'blah'); - }, 'blah: expected 6 to be above 10'); + expect(6).to.not.be.at.most(10, 'blah'); + (6).should.not.be.at.most(10, 'blah'); - err(() => { - expect('foo').to.have.length.of.at.most(2, 'blah'); - 'foo'.should.have.length.of.at.most(2, 'blah'); - }, 'blah: expected \'foo\' to have a length at most 2 but got 3'); + expect('foo').to.have.length.of.at.most(2, 'blah'); + 'foo'.should.have.length.of.at.most(2, 'blah'); - err(() => { - expect([1, 2, 3]).to.have.length.of.at.most(2, 'blah'); - [1, 2, 3].should.have.length.of.at.most(2, 'blah'); - }, 'blah: expected [ 1, 2, 3 ] to have a length at most 2 but got 3'); + expect([1, 2, 3]).to.have.length.of.at.most(2, 'blah'); + [1, 2, 3].should.have.length.of.at.most(2, 'blah'); - err(() => { - expect([1, 2]).to.not.have.length.of.at.most(2, 'blah'); - [1, 2].should.not.have.length.of.at.most(2, 'blah'); - }, 'blah: expected [ 1, 2 ] to have a length above 2'); + expect([1, 2]).to.not.have.length.of.at.most(2, 'blah'); + [1, 2].should.not.have.length.of.at.most(2, 'blah'); } function match() { @@ -394,15 +312,11 @@ function match() { expect('foobar').matches(/^foo/); 'foobar'.should.not.matches(/^bar/); - err(() => { - expect('foobar').to.match(/^bar/i, 'blah'); - 'foobar'.should.match(/^bar/i, 'blah'); - }, 'blah: expected \'foobar\' to match /^bar/i'); + expect('foobar').to.match(/^bar/i, 'blah'); + 'foobar'.should.match(/^bar/i, 'blah'); - err(() => { - expect('foobar').to.not.match(/^foo/i, 'blah'); - 'foobar'.should.not.match(/^foo/i, 'blah'); - }, 'blah: expected \'foobar\' not to match /^foo/i'); + expect('foobar').to.not.match(/^foo/i, 'blah'); + 'foobar'.should.not.match(/^foo/i, 'blah'); } function length2() { @@ -413,15 +327,11 @@ function length2() { expect([1, 2, 3]).to.have.length(3); [1, 2, 3].should.have.length(3); - err(() => { - expect(4).to.have.length(3, 'blah'); - (4).should.have.length(3, 'blah'); - }, 'blah: expected 4 to have a property \'length\''); + expect(4).to.have.length(3, 'blah'); + (4).should.have.length(3, 'blah'); - err(() => { - expect('asd').to.not.have.length(3, 'blah'); - 'asd'.should.not.have.length(3, 'blah'); - }, 'blah: expected \'asd\' to not have a length of 3'); + expect('asd').to.not.have.length(3, 'blah'); + 'asd'.should.not.have.length(3, 'blah'); } function eql() { @@ -434,10 +344,8 @@ function eql() { expect('4').to.not.eql(4); '4'.should.not.eql(4); - err(() => { - expect(4).to.eql(3, 'blah'); - (4).should.eql(3, 'blah'); - }, 'blah: expected 4 to deeply equal 3'); + expect(4).to.eql(3, 'blah'); + (4).should.eql(3, 'blah'); } class Buffer { @@ -448,10 +356,8 @@ function buffer() { expect(new Buffer([1])).to.eql(new Buffer([1])); (new Buffer([1])).should.eql(new Buffer([1])); - err(() => { - expect(new Buffer([0])).to.eql(new Buffer([1])); - (new Buffer([0])).should.eql(new Buffer([1])); - }, 'expected to deeply equal '); + expect(new Buffer([0])).to.eql(new Buffer([1])); + (new Buffer([0])).should.eql(new Buffer([1])); } function equal2() { @@ -462,17 +368,13 @@ function equal2() { (1).should.equal(1); should.equal(1, 1); - err(() => { - expect(4).to.equal(3, 'blah'); - (4).should.equal(3, 'blah'); - should.equal(4, 3, 'blah'); - }, 'blah: expected 4 to equal 3'); + expect(4).to.equal(3, 'blah'); + (4).should.equal(3, 'blah'); + should.equal(4, 3, 'blah'); - err(() => { - expect('4').to.equal(4, 'blah'); - '4'.should.equal(4, 'blah'); - should.equal(4, 4, 'blah'); - }, 'blah: expected \'4\' to equal 4'); + expect('4').to.equal(4, 'blah'); + '4'.should.equal(4, 'blah'); + should.equal(4, 4, 'blah'); } function deepEqual() { @@ -497,10 +399,9 @@ function deepEqual2() { expect(/a/m).not.to.deep.equal(/b/m); } -// ReSharper disable once InconsistentNaming function deepEqual3() { - var a = new Date(1, 2, 3); - var b = new Date(4, 5, 6); + const a = new Date(1, 2, 3); + const b = new Date(4, 5, 6); expect(a).to.deep.equal(a); a.should.deep.equal(a); expect(a).not.to.deep.equal(b); @@ -541,46 +442,30 @@ function empty() { expect({ foo: 'bar' }).not.to.be.empty; ({ foo: 'bar' }).should.not.be.empty; - err(() => { - expect('').not.to.be.empty; - ''.should.not.be.empty; - }, 'expected \'\' not to be empty'); + expect('').not.to.be.empty; + ''.should.not.be.empty; - err(() => { - expect('foo').to.be.empty; - 'foo'.should.be.empty; - 'foo'.should.be.empty; - }, 'expected \'foo\' to be empty'); + expect('foo').to.be.empty; + 'foo'.should.be.empty; + 'foo'.should.be.empty; - err(() => { - expect([]).not.to.be.empty; - [].should.not.be.empty; - }, 'expected [] not to be empty'); + expect([]).not.to.be.empty; + [].should.not.be.empty; - err(() => { - expect(['foo']).to.be.empty; - ['foo'].should.be.empty; - }, 'expected [ \'foo\' ] to be empty'); + expect(['foo']).to.be.empty; + ['foo'].should.be.empty; - err(() => { - expect(new FakeArgs).not.to.be.empty; - (new FakeArgs).should.not.be.empty; - }, 'expected { length: 0 } not to be empty'); + expect(new FakeArgs).not.to.be.empty; + (new FakeArgs).should.not.be.empty; - err(() => { - expect({ arguments: 0 }).to.be.empty; - ({ arguments: 0 }).should.be.empty; - }, 'expected { arguments: 0 } to be empty'); + expect({ arguments: 0 }).to.be.empty; + ({ arguments: 0 }).should.be.empty; - err(() => { - expect({}).not.to.be.empty; - ({}).should.not.be.empty; - }, 'expected {} not to be empty'); + expect({}).not.to.be.empty; + ({}).should.not.be.empty; - err(() => { - expect({ foo: 'bar' }).to.be.empty; - ({ foo: 'bar' }).should.be.empty; - }, 'expected { foo: \'bar\' } to be empty'); + expect({ foo: 'bar' }).to.be.empty; + ({ foo: 'bar' }).should.be.empty; } function property() { @@ -596,15 +481,13 @@ function property() { .to.not.have.property('foo.bar'); ({ foo: { bar: 'baz' } }).should.not.have.property('foo.bar'); - err(() => { - expect('asd').to.have.property('foo'); - 'asd'.should.have.property('foo'); - }, 'expected \'asd\' to have a property \'foo\''); - err(() => { - expect({ foo: { bar: 'baz' } }) - .to.have.property('foo.bar'); - ({ foo: { bar: 'baz' } }).should.have.property('foo.bar'); - }, 'expected { foo: { bar: \'baz\' } } to have a property \'foo.bar\''); + expect('asd').to.have.property('foo'); + 'asd'.should.have.property('foo'); + + expect({ foo: { bar: 'baz' } }) + .to.have.property('foo.bar'); + + ({ foo: { bar: 'baz' } }).should.have.property('foo.bar'); } function deepProperty() { @@ -617,12 +500,10 @@ function deepProperty() { ({ foo: { bar: 'baz' } }).should .have.deep.property('foo.bar'); - err(() => { - expect({ 'foo.bar': 'baz' }) - .to.have.deep.property('foo.bar'); - ({ 'foo.bar': 'baz' }).should - .have.deep.property('foo.bar'); - }, 'expected { \'foo.bar\': \'baz\' } to have a deep property \'foo.bar\''); + expect({ 'foo.bar': 'baz' }) + .to.have.deep.property('foo.bar'); + ({ 'foo.bar': 'baz' }).should + .have.deep.property('foo.bar'); } function property2() { @@ -631,25 +512,17 @@ function property2() { expect('asd').to.have.property('constructor', String); 'asd'.should.have.property('constructor', String); - err(() => { - expect('asd').to.have.property('length', 4, 'blah'); - 'asd'.should.have.property('length', 4, 'blah'); - }, 'blah: expected \'asd\' to have a property \'length\' of 4, but got 3'); + expect('asd').to.have.property('length', 4, 'blah'); + 'asd'.should.have.property('length', 4, 'blah'); - err(() => { - expect('asd').to.not.have.property('length', 3, 'blah'); - 'asd'.should.not.have.property('length', 3, 'blah'); - }, 'blah: expected \'asd\' to not have a property \'length\' of 3'); + expect('asd').to.not.have.property('length', 3, 'blah'); + 'asd'.should.not.have.property('length', 3, 'blah'); - err(() => { - expect('asd').to.not.have.property('foo', 3, 'blah'); - 'asd'.should.not.have.property('foo', 3, 'blah'); - }, 'blah: \'asd\' has no property \'foo\''); + expect('asd').to.not.have.property('foo', 3, 'blah'); + 'asd'.should.not.have.property('foo', 3, 'blah'); - err(() => { - expect('asd').to.have.property('constructor', Number, 'blah'); - 'asd'.should.have.property('constructor', Number, 'blah'); - }, 'blah: expected \'asd\' to have a property \'constructor\' of [Function: Number], but got [Function: String]'); + expect('asd').to.have.property('constructor', Number, 'blah'); + 'asd'.should.have.property('constructor', Number, 'blah'); } function deepProperty2() { @@ -658,24 +531,18 @@ function deepProperty2() { ({ foo: { bar: 'baz' } }).should .have.deep.property('foo.bar', 'baz'); - err(() => { - expect({ foo: { bar: 'baz' } }) - .to.have.deep.property('foo.bar', 'quux', 'blah'); - ({ foo: { bar: 'baz' } }).should - .have.deep.property('foo.bar', 'quux', 'blah'); - }, 'blah: expected { foo: { bar: \'baz\' } } to have a deep property \'foo.bar\' of \'quux\', but got \'baz\''); - err(() => { - expect({ foo: { bar: 'baz' } }) - .to.not.have.deep.property('foo.bar', 'baz', 'blah'); - ({ foo: { bar: 'baz' } }).should - .not.have.deep.property('foo.bar', 'baz', 'blah'); - }, 'blah: expected { foo: { bar: \'baz\' } } to not have a deep property \'foo.bar\' of \'baz\''); - err(() => { - expect({ foo: 5 }) - .to.not.have.deep.property('foo.bar', 'baz', 'blah'); - ({ foo: 5 }).should - .not.have.deep.property('foo.bar', 'baz', 'blah'); - }, 'blah: { foo: 5 } has no deep property \'foo.bar\''); + expect({ foo: { bar: 'baz' } }) + .to.have.deep.property('foo.bar', 'quux', 'blah'); + ({ foo: { bar: 'baz' } }).should + .have.deep.property('foo.bar', 'quux', 'blah'); + expect({ foo: { bar: 'baz' } }) + .to.not.have.deep.property('foo.bar', 'baz', 'blah'); + ({ foo: { bar: 'baz' } }).should + .not.have.deep.property('foo.bar', 'baz', 'blah'); + expect({ foo: 5 }) + .to.not.have.deep.property('foo.bar', 'baz', 'blah'); + ({ foo: 5 }).should + .not.have.deep.property('foo.bar', 'baz', 'blah'); } function ownProperty() { @@ -686,10 +553,8 @@ function ownProperty() { expect({ length: 12 }).to.have.ownProperty('length'); ({ length: 12 }).should.have.ownProperty('length'); - err(() => { - expect({ length: 12 }).to.not.have.ownProperty('length', 'blah'); - ({ length: 12 }).should.not.have.ownProperty('length', 'blah'); - }, 'blah: expected { length: 12 } to not have own property \'length\''); + expect({ length: 12 }).to.not.have.ownProperty('length', 'blah'); + ({ length: 12 }).should.not.have.ownProperty('length', 'blah'); } function ownPropertyDescriptor() { @@ -714,20 +579,14 @@ function string() { expect('foobar').to.not.have.string('baz'); 'foobar'.should.not.have.string('baz'); - err(() => { - expect(3).to.have.string('baz'); - (3).should.have.string('baz'); - }, 'expected 3 to be a string'); + expect(3).to.have.string('baz'); + (3).should.have.string('baz'); - err(() => { - expect('foobar').to.have.string('baz', 'blah'); - 'foobar'.should.have.string('baz', 'blah'); - }, 'blah: expected \'foobar\' to contain \'baz\''); + expect('foobar').to.have.string('baz', 'blah'); + 'foobar'.should.have.string('baz', 'blah'); - err(() => { - expect('foobar').to.not.have.string('bar', 'blah'); - 'foobar'.should.not.have.string('bar', 'blah'); - }, 'blah: expected \'foobar\' to not contain \'bar\''); + expect('foobar').to.not.have.string('bar', 'blah'); + 'foobar'.should.not.have.string('bar', 'blah'); } function include() { @@ -743,20 +602,15 @@ function include() { ['foo', 'bar'].should.not.include('baz'); expect(['foo', 'bar']).to.not.include(1); ['foo', 'bar'].should.not.include(1); - // alias expect(['foo', 'bar']).includes('foo'); ['foo', 'bar'].should.includes('foo'); - err(() => { - expect(['foo']).to.include('bar', 'blah'); - ['foo'].should.include('bar', 'blah'); - }, 'blah: expected [ \'foo\' ] to include \'bar\''); + expect(['foo']).to.include('bar', 'blah'); + ['foo'].should.include('bar', 'blah'); - err(() => { - expect(['bar', 'foo']).to.not.include('foo', 'blah'); - ['bar', 'foo'].should.not.include('foo', 'blah'); - }, 'blah: expected [ \'bar\', \'foo\' ] to not include \'foo\''); + expect(['bar', 'foo']).to.not.include('foo', 'blah'); + ['bar', 'foo'].should.not.include('foo', 'blah'); } function keys() { @@ -803,76 +657,50 @@ function keys() { expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz', 'foo'); ({ foo: 1, bar: 2 }).should.not.contain.keys('baz', 'foo'); - err(() => { - expect({ foo: 1 }).to.have.keys(); - ({ foo: 1 }).should.have.keys(); - }, 'keys required'); + expect({ foo: 1 }).to.have.keys(); + ({ foo: 1 }).should.have.keys(); - err(() => { - expect({ foo: 1 }).to.have.keys([]); - ({ foo: 1 }).should.have.keys([]); - }, 'keys required'); + expect({ foo: 1 }).to.have.keys([]); + ({ foo: 1 }).should.have.keys([]); - err(() => { - expect({ foo: 1 }).to.not.have.keys([]); - ({ foo: 1 }).should.not.have.keys([]); - }, 'keys required'); + expect({ foo: 1 }).to.not.have.keys([]); + ({ foo: 1 }).should.not.have.keys([]); - err(() => { - expect({ foo: 1 }).to.contain.keys([]); - ({ foo: 1 }).should.contain.keys([]); - }, 'keys required'); + expect({ foo: 1 }).to.contain.keys([]); + ({ foo: 1 }).should.contain.keys([]); - err(() => { - expect({ foo: 1 }).to.have.keys(['bar']); - ({ foo: 1 }).should.have.keys(['bar']); - }, 'expected { foo: 1 } to have key \'bar\''); + expect({ foo: 1 }).to.have.keys(['bar']); + ({ foo: 1 }).should.have.keys(['bar']); - err(() => { - expect({ foo: 1 }).to.have.keys(['bar', 'baz']); - ({ foo: 1 }).should.have.keys(['bar', 'baz']); - }, 'expected { foo: 1 } to have keys \'bar\', and \'baz\''); + expect({ foo: 1 }).to.have.keys(['bar', 'baz']); + ({ foo: 1 }).should.have.keys(['bar', 'baz']); - err(() => { - expect({ foo: 1 }).to.have.keys(['foo', 'bar', 'baz']); - ({ foo: 1 }).should.have.keys(['foo', 'bar', 'baz']); - }, 'expected { foo: 1 } to have keys \'foo\', \'bar\', and \'baz\''); + expect({ foo: 1 }).to.have.keys(['foo', 'bar', 'baz']); + ({ foo: 1 }).should.have.keys(['foo', 'bar', 'baz']); - err(() => { - expect({ foo: 1 }).to.not.have.keys(['foo']); - ({ foo: 1 }).should.not.have.keys(['foo']); - }, 'expected { foo: 1 } to not have key \'foo\''); + expect({ foo: 1 }).to.not.have.keys(['foo']); + ({ foo: 1 }).should.not.have.keys(['foo']); - err(() => { - expect({ foo: 1 }).to.not.have.keys(['foo']); - ({ foo: 1 }).should.not.have.keys(['foo']); - }, 'expected { foo: 1 } to not have key \'foo\''); + expect({ foo: 1 }).to.not.have.keys(['foo']); + ({ foo: 1 }).should.not.have.keys(['foo']); - err(() => { - expect({ foo: 1, bar: 2 }).to.not.have.keys(['foo', 'bar']); - ({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']); - }, 'expected { foo: 1, bar: 2 } to not have keys \'foo\', and \'bar\''); + expect({ foo: 1, bar: 2 }).to.not.have.keys(['foo', 'bar']); + ({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']); - err(() => { - expect({ foo: 1 }).to.not.contain.keys(['foo']); - ({ foo: 1 }).should.not.contain.keys(['foo']); - }, 'expected { foo: 1 } to not contain key \'foo\''); + expect({ foo: 1 }).to.not.contain.keys(['foo']); + ({ foo: 1 }).should.not.contain.keys(['foo']); - err(() => { - expect({ foo: 1 }).to.contain.keys('foo', 'bar'); - ({ foo: 1 }).should.contain.keys('foo', 'bar'); - }, 'expected { foo: 1 } to contain keys \'foo\', and \'bar\''); + expect({ foo: 1 }).to.contain.keys('foo', 'bar'); + ({ foo: 1 }).should.contain.keys('foo', 'bar'); } function chaining() { - var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] }; + const tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] }; expect(tea).to.have.property('extras').with.lengthOf(3); tea.should.have.property('extras').with.lengthOf(3); - err(() => { - expect(tea).to.have.property('extras').with.lengthOf(4); - tea.should.have.property('extras').with.lengthOf(4); - }, 'expected [ \'milk\', \'sugar\', \'smile\' ] to have a length of 4 but got 3'); + expect(tea).to.have.property('extras').with.lengthOf(4); + tea.should.have.property('extras').with.lengthOf(4); expect(tea).to.be.a('object').and.have.property('name', 'chai'); tea.should.be.a('object').and.have.property('name', 'chai'); @@ -906,9 +734,9 @@ function _throw() { // only set the name inside the constructor itself. PoorlyConstructedError.prototype = Object.create(Error.prototype); - var specificError = new RangeError('boo'); + const specificError = new RangeError('boo'); - var goodFn = () => { } + const goodFn = () => { } , badFn = () => { throw new Error('testing'); } , refErrFn = () => { throw new ReferenceError('hello'); } , ickyErrFn = () => { throw new PoorlyConstructedError(); } @@ -989,116 +817,80 @@ function _throw() { badFn.should.throw(Error, 'testing'); should.throw(badFn, Error, 'testing'); - err(() => { - expect(goodFn).to.throw(); - goodFn.should.throw(); - should.throw(goodFn); - }, 'expected [Function] to throw an error'); + expect(goodFn).to.throw(); + goodFn.should.throw(); + should.throw(goodFn); - err(() => { - expect(goodFn).to.throw(ReferenceError); - goodFn.should.throw(ReferenceError); - should.throw(goodFn, ReferenceError); - }, 'expected [Function] to throw ReferenceError'); + expect(goodFn).to.throw(ReferenceError); + goodFn.should.throw(ReferenceError); + should.throw(goodFn, ReferenceError); - err(() => { - expect(goodFn).to.throw(specificError); - goodFn.should.throw(specificError); - should.throw(goodFn, specificError); - }, 'expected [Function] to throw [RangeError: boo]'); + expect(goodFn).to.throw(specificError); + goodFn.should.throw(specificError); + should.throw(goodFn, specificError); - err(() => { - expect(badFn).to.not.throw(); - badFn.should.not.throw(); - should.not.throw(badFn); - }, 'expected [Function] to not throw an error but [Error: testing] was thrown'); + expect(badFn).to.not.throw(); + badFn.should.not.throw(); + should.not.throw(badFn); - err(() => { - expect(badFn).to.throw(ReferenceError); - badFn.should.throw(ReferenceError); - should.throw(badFn, ReferenceError); - }, 'expected [Function] to throw \'ReferenceError\' but [Error: testing] was thrown'); + expect(badFn).to.throw(ReferenceError); + badFn.should.throw(ReferenceError); + should.throw(badFn, ReferenceError); - err(() => { - expect(badFn).to.throw(specificError); - badFn.should.throw(specificError); - should.throw(badFn, specificError); - }, 'expected [Function] to throw [RangeError: boo] but [Error: testing] was thrown'); + expect(badFn).to.throw(specificError); + badFn.should.throw(specificError); + should.throw(badFn, specificError); - err(() => { - expect(badFn).to.not.throw(Error); - badFn.should.not.throw(Error); - should.not.throw(badFn, Error); - }, 'expected [Function] to not throw \'Error\' but [Error: testing] was thrown'); + expect(badFn).to.not.throw(Error); + badFn.should.not.throw(Error); + should.not.throw(badFn, Error); - err(() => { - expect(refErrFn).to.not.throw(ReferenceError); - refErrFn.should.not.throw(ReferenceError); - should.not.throw(refErrFn, ReferenceError); - }, 'expected [Function] to not throw \'ReferenceError\' but [ReferenceError: hello] was thrown'); + expect(refErrFn).to.not.throw(ReferenceError); + refErrFn.should.not.throw(ReferenceError); + should.not.throw(refErrFn, ReferenceError); - err(() => { - expect(badFn).to.throw(PoorlyConstructedError); - badFn.should.throw(PoorlyConstructedError); - should.throw(badFn, PoorlyConstructedError); - }, 'expected [Function] to throw \'PoorlyConstructedError\' but [Error: testing] was thrown'); + expect(badFn).to.throw(PoorlyConstructedError); + badFn.should.throw(PoorlyConstructedError); + should.throw(badFn, PoorlyConstructedError); - err(() => { - expect(ickyErrFn).to.not.throw(PoorlyConstructedError); - ickyErrFn.should.not.throw(PoorlyConstructedError); - should.not.throw(ickyErrFn, PoorlyConstructedError); - }, /^(expected \[Function\] to not throw 'PoorlyConstructedError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/); + expect(ickyErrFn).to.not.throw(PoorlyConstructedError); + ickyErrFn.should.not.throw(PoorlyConstructedError); + should.not.throw(ickyErrFn, PoorlyConstructedError); - err(() => { - expect(ickyErrFn).to.throw(ReferenceError); - ickyErrFn.should.throw(ReferenceError); - should.throw(ickyErrFn, ReferenceError); - }, /^(expected \[Function\] to throw 'ReferenceError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/); + expect(ickyErrFn).to.throw(ReferenceError); + ickyErrFn.should.throw(ReferenceError); + should.throw(ickyErrFn, ReferenceError); - err(() => { - expect(specificErrFn).to.throw(new ReferenceError('eek')); - specificErrFn.should.throw(new ReferenceError('eek')); - should.throw(specificErrFn, new ReferenceError('eek')); - }, 'expected [Function] to throw [ReferenceError: eek] but [RangeError: boo] was thrown'); + expect(specificErrFn).to.throw(new ReferenceError('eek')); + specificErrFn.should.throw(new ReferenceError('eek')); + should.throw(specificErrFn, new ReferenceError('eek')); - err(() => { - expect(specificErrFn).to.not.throw(specificError); - specificErrFn.should.not.throw(specificError); - should.not.throw(specificErrFn, specificError); - }, 'expected [Function] to not throw [RangeError: boo]'); + expect(specificErrFn).to.not.throw(specificError); + specificErrFn.should.not.throw(specificError); + should.not.throw(specificErrFn, specificError); - err(() => { - expect(badFn).to.not.throw(/testing/); - badFn.should.not.throw(/testing/); - should.not.throw(badFn, /testing/); - }, 'expected [Function] to throw error not matching /testing/'); + expect(badFn).to.not.throw(/testing/); + badFn.should.not.throw(/testing/); + should.not.throw(badFn, /testing/); - err(() => { - expect(badFn).to.throw(/hello/); - badFn.should.throw(/hello/); - should.throw(badFn, /hello/); - }, 'expected [Function] to throw error matching /hello/ but got \'testing\''); + expect(badFn).to.throw(/hello/); + badFn.should.throw(/hello/); + should.throw(badFn, /hello/); - err(() => { - expect(badFn).to.throw(Error, /hello/, 'blah'); - badFn.should.throw(Error, /hello/, 'blah'); - should.throw(badFn, Error, /hello/, 'blah'); - }, 'blah: expected [Function] to throw error matching /hello/ but got \'testing\''); + expect(badFn).to.throw(Error, /hello/, 'blah'); + badFn.should.throw(Error, /hello/, 'blah'); + should.throw(badFn, Error, /hello/, 'blah'); - err(() => { - expect(badFn).to.throw(Error, 'hello', 'blah'); - badFn.should.throw(Error, 'hello', 'blah'); - should.throw(badFn, Error, 'hello', 'blah'); - }, 'blah: expected [Function] to throw error including \'hello\' but got \'testing\''); + expect(badFn).to.throw(Error, 'hello', 'blah'); + badFn.should.throw(Error, 'hello', 'blah'); + should.throw(badFn, Error, 'hello', 'blah'); } function use() { - // ReSharper disable once InconsistentNaming chai.use((_chai) => { _chai.can.use.any(); }); - // chain style: use mulptile plug-ins let expect = chai .use((_chai, util) => {}) .use((_chai, util) => {}) @@ -1114,7 +906,7 @@ class Klass { } function respondTo() { - var obj = new Klass(); + const obj = new Klass(); expect(Klass).to.respondTo('bar'); expect(obj).respondsTo('bar'); @@ -1128,15 +920,11 @@ function respondTo() { expect(obj).not.to.respondTo('foo'); obj.should.not.respondTo('foo'); - err(() => { - expect(Klass).to.respondTo('baz', 'constructor'); - Klass.should.respondTo('baz', 'constructor'); - }, /^(constructor: expected)(.*)(\[Function: Klass\])(.*)(to respond to \'baz\')$/); + expect(Klass).to.respondTo('baz', 'constructor'); + Klass.should.respondTo('baz', 'constructor'); - err(() => { - expect(obj).to.respondTo('baz', 'object'); - obj.should.respondTo('baz', 'object'); - }, /^(object: expected)(.*)(\{ foo: \[Function\] \}|\{ Object \()(.*)(to respond to \'baz\')$/); + expect(obj).to.respondTo('baz', 'object'); + obj.should.respondTo('baz', 'object'); } function satisfy() { @@ -1147,10 +935,8 @@ function satisfy() { expect(1).to.satisfy(matcher); (1).should.satisfy(matcher); - err(() => { - expect(2).to.satisfy(matcher, 'blah'); - (2).should.satisfy(matcher, 'blah'); - }, 'blah: expected 2 to satisfy [Function: matcher]'); + expect(2).to.satisfy(matcher, 'blah'); + (2).should.satisfy(matcher, 'blah'); } function closeTo() { @@ -1161,15 +947,11 @@ function closeTo() { expect(-10).to.be.closeTo(20, 30); (-10).should.be.closeTo(20, 30); - err(() => { - expect(2).to.be.closeTo(1.0, 0.5, 'blah'); - (2).should.be.closeTo(1.0, 0.5, 'blah'); - }, 'blah: expected 2 to be close to 1 +/- 0.5'); + expect(2).to.be.closeTo(1.0, 0.5, 'blah'); + (2).should.be.closeTo(1.0, 0.5, 'blah'); - err(() => { - expect(-10).to.be.closeTo(20, 29, 'blah'); - (-10).should.be.closeTo(20, 29, 'blah'); - }, 'blah: expected -10 to be close to 20 +/- 29'); + expect(-10).to.be.closeTo(20, 29, 'blah'); + (-10).should.be.closeTo(20, 29, 'blah'); } function approximately() { @@ -1180,15 +962,11 @@ function approximately() { expect(-10).to.be.approximately(20, 30); (-10).should.be.approximately(20, 30); - err(() => { - expect(2).to.be.approximately(1.0, 0.5, 'blah'); - (2).should.be.approximately(1.0, 0.5, 'blah'); - }, 'blah: expected 2 to be close to 1 +/- 0.5'); + expect(2).to.be.approximately(1.0, 0.5, 'blah'); + (2).should.be.approximately(1.0, 0.5, 'blah'); - err(() => { - expect(-10).to.be.approximately(20, 29, 'blah'); - (-10).should.be.approximately(20, 29, 'blah'); - }, 'blah: expected -10 to be close to 20 +/- 29'); + expect(-10).to.be.approximately(20, 29, 'blah'); + (-10).should.be.approximately(20, 29, 'blah'); } function includeMembers() { @@ -1249,10 +1027,10 @@ function members() { } function increaseDecreaseChange() { - var obj = { val: 10 }; - var inc = () => { obj.val++; }; - var dec = () => { obj.val--; }; - var same = () => { }; + const obj = { val: 10 }; + const inc = () => { obj.val++; }; + const dec = () => { obj.val--; }; + const same = () => { }; expect(inc).to.increase(obj, "val"); expect(inc).increases(obj, "val"); @@ -1281,7 +1059,7 @@ function increaseDecreaseChange() { } function oneOf() { - var obj = { z: 3 }; + const obj = { z: 3 }; expect(5).to.be.oneOf([1, 5, 4]); expect('z').to.be.oneOf(['x', 'y', 'z']); @@ -1311,28 +1089,17 @@ class CrashyObject { suite('assert', () => { test('assert', () => { - var foo = 'bar'; + const foo: string = 'bar'; assert(foo === 'bar', 'expected foo to equal `bar`'); - err(() => { - assert(foo === 'baz', 'expected foo to equal `bar`'); - }, 'expected foo to equal `bar`'); + assert(foo === 'baz', 'expected foo to equal `bar`'); }); test('isTrue', () => { assert.isTrue(true); - - err(() => { - assert.isTrue(false); - }, 'expected false to be true'); - - err(() => { - assert.isTrue(1); - }, 'expected 1 to be true'); - - err(() => { - assert.isTrue('test'); - }, 'expected \'test\' to be true'); + assert.isTrue(false); + assert.isTrue(1); + assert.isTrue('test'); }); test('ok', () => { @@ -1342,18 +1109,9 @@ suite('assert', () => { assert.isOk(true); assert.isOk(1); assert.isOk('test'); - - err(() => { - assert.ok(false); - }, 'expected false to be truthy'); - - err(() => { - assert.ok(0); - }, 'expected 0 to be truthy'); - - err(() => { - assert.ok(''); - }, 'expected \'\' to be truthy'); + assert.ok(false); + assert.ok(0); + assert.ok(''); }); test('notOk', () => { @@ -1363,30 +1121,15 @@ suite('assert', () => { assert.isNotOk(false); assert.isNotOk(0); assert.isNotOk(''); - - err(() => { - assert.notOk(true); - }, 'expected true to be falsy'); - - err(() => { - assert.notOk(1); - }, 'expected 1 to be falsy'); - - err(() => { - assert.notOk('test'); - }, 'expected \'test\' to be falsy'); + assert.notOk(true); + assert.notOk(1); + assert.notOk('test'); }); test('isFalse', () => { assert.isFalse(false); - - err(() => { - assert.isFalse(true); - }, 'expected true to be false'); - - err(() => { - assert.isFalse(0); - }, 'expected 0 to be false'); + assert.isFalse(true); + assert.isFalse(0); }); test('equal', () => { @@ -1397,387 +1140,235 @@ suite('assert', () => { assert.typeOf('test', 'string'); assert.typeOf(true, 'boolean'); assert.typeOf(5, 'number'); - - err(() => { - assert.typeOf(5, 'string'); - }, 'expected 5 to be a string'); - + assert.typeOf(5, 'string'); }); test('notTypeOf', () => { assert.notTypeOf('test', 'number'); - - err(() => { - assert.notTypeOf(5, 'number'); - }, 'expected 5 not to be a number'); + assert.notTypeOf(5, 'number'); }); test('instanceOf', () => { assert.instanceOf(new Foo(), Foo); - - err(() => { - assert.instanceOf(5, Foo); - }, 'expected 5 to be an instance of Foo'); + assert.instanceOf(5, Foo); assert.instanceOf(new CrashyObject(), CrashyObject); }); test('notInstanceOf', () => { assert.notInstanceOf(new Foo(), String); - - err(() => { - assert.notInstanceOf(new Foo(), Foo); - }, 'expected {} to not be an instance of Foo'); + assert.notInstanceOf(new Foo(), Foo); }); test('isObject', () => { assert.isObject({}); assert.isObject(new Foo()); - - err(() => { - assert.isObject(true); - }, 'expected true to be an object'); - - err(() => { - assert.isObject(Foo); - }, 'expected [Function: Foo] to be an object'); - - err(() => { - assert.isObject('foo'); - }, 'expected \'foo\' to be an object'); + assert.isObject(true); + assert.isObject(Foo); + assert.isObject('foo'); }); test('isNotObject', () => { assert.isNotObject(5); - - err(() => { - assert.isNotObject({}); - }, 'expected {} not to be an object'); + assert.isNotObject({}); }); test('notEqual', () => { assert.notEqual(3, 4); - - err(() => { - assert.notEqual(5, 5); - }, 'expected 5 to not equal 5'); + assert.notEqual(5, 5); }); test('strictEqual', () => { assert.strictEqual('foo', 'foo'); - - err(() => { - assert.strictEqual('5', 5); - }, 'expected \'5\' to equal 5'); }); test('notStrictEqual', () => { - assert.notStrictEqual(5, '5'); - - err(() => { - assert.notStrictEqual(5, 5); - }, 'expected 5 to not equal 5'); + assert.notStrictEqual(5, 5); }); test('deepEqual', () => { assert.deepEqual({ tea: 'chai' }, { tea: 'chai' }); + assert.deepEqual({ tea: 'chai' }, { tea: 'black' }); - err(() => { - assert.deepEqual({ tea: 'chai' }, { tea: 'black' }); - }, 'expected { tea: \'chai\' } to deeply equal { tea: \'black\' }'); - - var obja = Object.create({ tea: 'chai' }) + const obja = Object.create({ tea: 'chai' }) , objb = Object.create({ tea: 'chai' }); assert.deepEqual(obja, objb); - var obj1 = Object.create({ tea: 'chai' }) + const obj1 = Object.create({ tea: 'chai' }) , obj2 = Object.create({ tea: 'black' }); - err(() => { - assert.deepEqual(obj1, obj2); - }, 'expected { tea: \'chai\' } to deeply equal { tea: \'black\' }'); + assert.deepEqual(obj1, obj2); }); test('deepEqual (ordering)', () => { - var a = { a: 'b', c: 'd' } + const a = { a: 'b', c: 'd' } , b = { c: 'd', a: 'b' }; assert.deepEqual(a, b); }); test('deepEqual (circular)', () => { - var circularObject: any = {} + const circularObject: any = {} , secondCircularObject: any = {}; circularObject.field = circularObject; secondCircularObject.field = secondCircularObject; assert.deepEqual(circularObject, secondCircularObject); - err(() => { - secondCircularObject.field2 = secondCircularObject; - assert.deepEqual(circularObject, secondCircularObject); - }, 'expected { field: [Circular] } to deeply equal { Object (field, field2) }'); + secondCircularObject.field2 = secondCircularObject; + assert.deepEqual(circularObject, secondCircularObject); }); test('notDeepEqual', () => { assert.notDeepEqual({ tea: 'jasmine' }, { tea: 'chai' }); - err(() => { - assert.notDeepEqual({ tea: 'chai' }, { tea: 'chai' }); - }, 'expected { tea: \'chai\' } to not deeply equal { tea: \'chai\' }'); + assert.notDeepEqual({ tea: 'chai' }, { tea: 'chai' }); }); test('notDeepEqual (circular)', () => { - var circularObject: any = {} + const circularObject: any = {} , secondCircularObject: any = { tea: 'jasmine' }; circularObject.field = circularObject; secondCircularObject.field = secondCircularObject; assert.notDeepEqual(circularObject, secondCircularObject); - err(() => { - delete secondCircularObject.tea; - assert.notDeepEqual(circularObject, secondCircularObject); - }, 'expected { field: [Circular] } to not deeply equal { field: [Circular] }'); + delete secondCircularObject.tea; + assert.notDeepEqual(circularObject, secondCircularObject); }); test('isNull', () => { assert.isNull(null); - - err(() => { - assert.isNull(undefined); - }, 'expected undefined to equal null'); + assert.isNull(undefined); }); test('isNotNull', () => { assert.isNotNull(undefined); - - err(() => { - assert.isNotNull(null); - }, 'expected null to not equal null'); + assert.isNotNull(null); }); test('isUndefined', () => { assert.isUndefined(undefined); - - err(() => { - assert.isUndefined(null); - }, 'expected null to equal undefined'); + assert.isUndefined(null); }); test('isDefined', () => { assert.isDefined(null); - - err(() => { - assert.isDefined(undefined); - }, 'expected undefined to not equal undefined'); + assert.isDefined(undefined); }); test('isNaN', () => { assert.isNaN(NaN); - - err(() => { - assert.isNaN(12); - }, 'expected 12 to be NaN'); + assert.isNaN(12); }); test('isNotNaN', () => { assert.isNotNaN(12); - - err(() => { - assert.isNotNaN(NaN); - }, 'expected NaN to not NaN'); + assert.isNotNaN(NaN); }); test('isFunction', () => { - var func = () => { + const func = () => { }; assert.isFunction(func); - - err(() => { - assert.isFunction({}); - }, 'expected {} to be a function'); + assert.isFunction({}); }); test('isNotFunction', () => { assert.isNotFunction(5); - - err(() => { - assert.isNotFunction(() => { - }); - }, 'expected [Function] not to be a function'); + assert.isNotFunction(() => {}); }); test('isArray', () => { assert.isArray([]); assert.isArray(new Array()); - - err(() => { - assert.isArray({}); - }, 'expected {} to be an array'); + assert.isArray({}); }); test('isNotArray', () => { assert.isNotArray(3); - - err(() => { - assert.isNotArray([]); - }, 'expected [] not to be an array'); - - err(() => { - assert.isNotArray(new Array()); - }, 'expected [] not to be an array'); + assert.isNotArray([]); + assert.isNotArray(new Array()); }); test('isString', () => { assert.isString('Foo'); assert.isString(new String('foo')); - - err(() => { - assert.isString(1); - }, 'expected 1 to be a string'); + assert.isString(1); }); test('isNotString', () => { assert.isNotString(3); assert.isNotString(['hello']); - - err(() => { - assert.isNotString('hello'); - }, 'expected \'hello\' not to be a string'); + assert.isNotString('hello'); }); test('isNumber', () => { assert.isNumber(1); assert.isNumber(Number('3')); - - err(() => { - assert.isNumber('1'); - }, 'expected \'1\' to be a number'); + assert.isNumber('1'); }); test('isNotNumber', () => { assert.isNotNumber('hello'); assert.isNotNumber([5]); - - err(() => { - assert.isNotNumber(4); - }, 'expected 4 not to be a number'); + assert.isNotNumber(4); }); test('isBoolean', () => { assert.isBoolean(true); assert.isBoolean(false); - - err(() => { - assert.isBoolean('1'); - }, 'expected \'1\' to be a boolean'); + assert.isBoolean('1'); }); test('isNotBoolean', () => { assert.isNotBoolean('true'); - - err(() => { - assert.isNotBoolean(true); - }, 'expected true not to be a boolean'); - - err(() => { - assert.isNotBoolean(false); - }, 'expected false not to be a boolean'); + assert.isNotBoolean(true); + assert.isNotBoolean(false); }); test('include', () => { assert.include('foobar', 'bar'); assert.include([1, 2, 3], 3); - - err(() => { - assert.include('foobar', 'baz'); - }, 'expected \'foobar\' to contain \'baz\''); - - err(() => { - assert.include(undefined, 'bar'); - }, 'expected an array or string'); + assert.include('foobar', 'baz'); + assert.include(undefined, 'bar'); }); test('notInclude', () => { assert.notInclude('foobar', 'baz'); assert.notInclude([1, 2, 3], 4); - - err(() => { - assert.notInclude('foobar', 'bar'); - }, 'expected \'foobar\' to not contain \'bar\''); - - err(() => { - assert.notInclude(undefined, 'bar'); - }, 'expected an array or string'); + assert.notInclude('foobar', 'bar'); + assert.notInclude(undefined, 'bar'); }); test('lengthOf', () => { assert.lengthOf([1, 2, 3], 3); assert.lengthOf('foobar', 6); - - err(() => { - assert.lengthOf('foobar', 5); - }, 'expected \'foobar\' to have a length of 5 but got 6'); - - err(() => { - assert.lengthOf(1, 5); - }, 'expected 1 to have a property \'length\''); + assert.lengthOf('foobar', 5); + assert.lengthOf(1, 5); }); test('match', () => { assert.match('foobar', /^foo/); assert.notMatch('foobar', /^bar/); - - err(() => { - assert.match('foobar', /^bar/i); - }, 'expected \'foobar\' to match /^bar/i'); - - err(() => { - assert.notMatch('foobar', /^foo/i); - }, 'expected \'foobar\' not to match /^foo/i'); + assert.match('foobar', /^bar/i); + assert.notMatch('foobar', /^foo/i); }); test('property', () => { - var obj = { foo: { bar: 'baz' } }; - var simpleObj = { foo: 'bar' }; + const obj = { foo: { bar: 'baz' } }; + const simpleObj = { foo: 'bar' } as any; assert.property(obj, 'foo'); assert.deepProperty(obj, 'foo.bar'); - assert.notProperty(obj, 'baz'); - assert.notProperty(obj, 'foo.bar'); assert.notDeepProperty(obj, 'foo.baz'); assert.deepPropertyVal(obj, 'foo.bar', 'baz'); - assert.deepPropertyNotVal(obj, 'foo.bar', 'flow'); - - err(() => { - assert.property(obj, 'baz'); - }, 'expected { foo: { bar: \'baz\' } } to have a property \'baz\''); - - err(() => { - assert.deepProperty(obj, 'foo.baz'); - }, 'expected { foo: { bar: \'baz\' } } to have a deep property \'foo.baz\''); - - err(() => { - assert.notProperty(obj, 'foo'); - }, 'expected { foo: { bar: \'baz\' } } to not have property \'foo\''); - - err(() => { - assert.notDeepProperty(obj, 'foo.bar'); - }, 'expected { foo: { bar: \'baz\' } } to not have deep property \'foo.bar\''); - - err(() => { - assert.propertyVal(simpleObj, 'foo', 'ball'); - }, 'expected { foo: \'bar\' } to have a property \'foo\' of \'ball\', but got \'bar\''); - - err(() => { - assert.deepPropertyVal(obj, 'foo.bar', 'ball'); - }, 'expected { foo: { bar: \'baz\' } } to have a deep property \'foo.bar\' of \'ball\', but got \'baz\''); - - err(() => { - assert.propertyNotVal(simpleObj, 'foo', 'bar'); - }, 'expected { foo: \'bar\' } to not have a property \'foo\' of \'bar\''); - - err(() => { - assert.deepPropertyNotVal(obj, 'foo.bar', 'baz'); - }, 'expected { foo: { bar: \'baz\' } } to not have a deep property \'foo.bar\' of \'baz\''); + assert.deepPropertyNotVal(simpleObj, 'foo.bar', 'flow'); + assert.property(simpleObj, 'baz'); + assert.deepProperty(obj, 'foo.baz'); + assert.notProperty(obj, 'foo'); + assert.notDeepProperty(obj, 'foo.bar'); + assert.propertyVal(simpleObj, 'foo', 'ball'); + assert.deepPropertyVal(obj, 'foo.bar', 'ball'); + assert.propertyNotVal(simpleObj, 'foo', 'bar'); + assert.deepPropertyNotVal(simpleObj, 'foo.bar', 'baz'); }); test('throws', () => { @@ -1797,69 +1388,47 @@ suite('assert', () => { throw new Error('bar'); }, Error, 'bar'); - err(() => { - assert.throws(() => { - throw new Error('foo'); - }, TypeError); - }, 'expected [Function] to throw \'TypeError\' but [Error: foo] was thrown'); + assert.throws(() => { + throw new Error('foo'); + }, TypeError); - err(() => { - assert.throws(() => { - throw new Error('foo'); - }, 'bar'); - }, 'expected [Function] to throw error including \'bar\' but got \'foo\''); + assert.throws(() => { + throw new Error('foo'); + }, 'bar'); - err(() => { - assert.throws(() => { - throw new Error('foo'); - }, Error, 'bar'); - }, 'expected [Function] to throw error including \'bar\' but got \'foo\''); + assert.throws(() => { + throw new Error('foo'); + }, Error, 'bar'); - err(() => { - assert.throws(() => { - throw new Error('foo'); - }, TypeError, 'bar'); - }, 'expected [Function] to throw \'TypeError\' but [Error: foo] was thrown'); + assert.throws(() => { + throw new Error('foo'); + }, TypeError, 'bar'); - err(() => { - assert.throws(() => { - }); - }, 'expected [Function] to throw an error'); + assert.throws(() => {}); - err(() => { - assert.throws(() => { - throw new Error(''); - }, 'bar'); - }, 'expected [Function] to throw error including \'bar\' but got \'\''); + assert.throws(() => { + throw new Error(''); + }, 'bar'); - err(() => { - assert.throws(() => { - throw new Error(''); - }, /bar/); - }, 'expected [Function] to throw error matching /bar/ but got \'\''); + assert.throws(() => { + throw new Error(''); + }, /bar/); }); test('doesNotThrow', () => { - assert.doesNotThrow(() => { - }); - assert.doesNotThrow(() => { - }, 'foo'); + assert.doesNotThrow(() => { }); + assert.doesNotThrow(() => { }, 'foo'); - err(() => { - assert.doesNotThrow(() => { - throw new Error('foo'); - }); - }, 'expected [Function] to not throw an error but [Error: foo] was thrown'); + assert.doesNotThrow(() => { + throw new Error('foo'); + }); }); test('ifError', () => { assert.ifError(false); assert.ifError(null); assert.ifError(undefined); - - err(() => { - assert.ifError('foo'); - }, 'expected \'foo\' to be falsy'); + assert.ifError('foo'); }); test('operator', () => { @@ -1870,117 +1439,58 @@ suite('assert', () => { assert.operator(1, '>=', 1); assert.operator(1, '!=', 2); assert.operator(1, '!==', 2); - - err(() => { - assert.operator(1, '=', 2); - }, 'Invalid operator "="'); - - err(() => { - assert.operator(2, '<', 1); - }, 'expected 2 to be < 1'); - - err(() => { - assert.operator(1, '>', 2); - }, 'expected 1 to be > 2'); - - err(() => { - assert.operator(1, '==', 2); - }, 'expected 1 to be == 2'); - - err(() => { - assert.operator(2, '<=', 1); - }, 'expected 2 to be <= 1'); - - err(() => { - assert.operator(1, '>=', 2); - }, 'expected 1 to be >= 2'); - - err(() => { - assert.operator(1, '!=', 1); - }, 'expected 1 to be != 1'); - - err(() => { - assert.operator(1, '!==', '1'); - }, 'expected 1 to be !== \'1\''); + assert.operator(2, '<', 1); + assert.operator(1, '>', 2); + assert.operator(1, '==', 2); + assert.operator(2, '<=', 1); + assert.operator(1, '>=', 2); + assert.operator(1, '!=', 1); + assert.operator(1, '!==', '1'); }); test('closeTo', () => { assert.closeTo(1.5, 1.0, 0.5); assert.closeTo(10, 20, 20); assert.closeTo(-10, 20, 30); - - err(() => { - assert.closeTo(2, 1.0, 0.5); - }, 'expected 2 to be close to 1 +/- 0.5'); - - err(() => { - assert.closeTo(-10, 20, 29); - }, 'expected -10 to be close to 20 +/- 29'); + assert.closeTo(2, 1.0, 0.5); + assert.closeTo(-10, 20, 29); }); test('approximately', () => { assert.approximately(1.5, 1.0, 0.5); assert.approximately(10, 20, 20); assert.approximately(-10, 20, 30); - - err(() => { - assert.approximately(2, 1.0, 0.5); - }, 'expected 2 to be close to 1 +/- 0.5'); - - err(() => { - assert.approximately(-10, 20, 29); - }, 'expected -10 to be close to 20 +/- 29'); + assert.approximately(2, 1.0, 0.5); + assert.approximately(-10, 20, 29); }); test('members', () => { assert.includeMembers([1, 2, 3], [2, 3]); assert.includeMembers([1, 2, 3], []); assert.includeMembers([1, 2, 3], [3]); - - err(() => { - assert.includeMembers([5, 6], [7, 8]); - }, 'expected [ 5, 6 ] to be a superset of [ 7, 8 ]'); - - err(() => { - assert.includeMembers([5, 6], [5, 6, 0]); - }, 'expected [ 5, 6 ] to be a superset of [ 5, 6, 0 ]'); + assert.includeMembers([5, 6], [7, 8]); + assert.includeMembers([5, 6], [5, 6, 0]); }); test('memberEquals', () => { assert.sameMembers([], []); assert.sameMembers([1, 2, 3], [3, 2, 1]); assert.sameMembers([4, 2], [4, 2]); - - err(() => { - assert.sameMembers([], [1, 2]); - }, 'expected [] to have the same members as [ 1, 2 ]'); - - err(() => { - assert.sameMembers([1, 54], [6, 1, 54]); - }, 'expected [ 1, 54 ] to have the same members as [ 6, 1, 54 ]'); + assert.sameMembers([], [1, 2]); + assert.sameMembers([1, 54], [6, 1, 54]); }); test('isAbove', () => { assert.isAbove(10, 5); - - err(() => { - assert.isAbove(1, 5); - }, 'expected 1 to be above 5'); - err(() => { - assert.isAbove(5, 5); - }, 'expected 5 to be above 5'); + assert.isAbove(1, 5); + assert.isAbove(5, 5); }); test('isBelow', () => { assert.isBelow(5, 10); - - err(() => { - assert.isBelow(5, 1); - }, 'expected 5 to be above 1'); - err(() => { - assert.isBelow(5, 5); - }, 'expected 5 to be below 5'); + assert.isBelow(5, 1); + assert.isBelow(5, 5); }); test('extensible', () => { assert.extensible({}); }); @@ -2000,53 +1510,153 @@ suite('assert', () => { test('isNotTrue', () => { assert.isNotTrue(false); - - err(() => { - assert.isNotTrue(true); - }, 'expected true to not be true'); + assert.isNotTrue(true); }); test('isNotFalse', () => { assert.isNotFalse(true); - - err(() => { - assert.isNotFalse(false); - }, 'expected false to not be false'); + assert.isNotFalse(false); }); test('isAtLeast', () => { assert.isAtLeast(5, 3); assert.isAtLeast(5, 5); - - err(() => { - assert.isAtLeast(3, 5); - }, 'expected 3 to be greater than or equal to 5'); + assert.isAtLeast(3, 5); }); test('isAtMost', () => { assert.isAtMost(3, 5); assert.isAtMost(5, 5); - - err(() => { - assert.isAtMost(5, 3); - }, 'expected 5 to be less than or equal to 3'); + assert.isAtMost(5, 3); }); test('oneOf', () => { - var obj = { z: 3 }; + const obj = { z: 3 }; assert.oneOf(5, [1, 5, 4]); assert.oneOf('z', ['x', 'y', 'z']); assert.oneOf(obj, [obj]); - - err(() => { - assert.oneOf(5, [1, [5], 4]); - }, 'expected 5 to be one of [1, [5], 4]'); - err(() => { - assert.oneOf('z', ['w', 'x', 'y']); - }, 'expected "z" to be one of [w, x, y]'); - err(() => { - assert.oneOf(obj, [{ z: 3 }]); - }, 'expected { z: 3 } to be one of [{ z: 3 }]'); + assert.oneOf(5, [1, [5], 4]); + assert.oneOf('z', ['w', 'x', 'y']); + assert.oneOf(obj, [{ z: 3 }]); }); -}); + + test('changes', () => { + const obj = { z: 3 }; + + assert.changes(() => {}, obj, 'z'); + assert.changes(() => {}, obj, 'z', 'message'); + }); + + test('doesNotChange', () => { + const obj = { z: 3 }; + + assert.doesNotChange(() => {}, obj, 'z'); + assert.doesNotChange(() => {}, obj, 'z', 'message'); + }); + + test('increases', () => { + const obj = { z: 3 }; + + assert.increases(() => {}, obj, 'z'); + assert.increases(() => {}, obj, 'z', 'message'); + }); + + test('doesNotIncrease', () => { + const obj = { z: 3 }; + + assert.doesNotIncrease(() => {}, obj, 'z'); + assert.doesNotIncrease(() => {}, obj, 'z', 'message'); + }); + + test('decreases', () => { + const obj = { z: 3 }; + + assert.decreases(() => {}, obj, 'z'); + assert.decreases(() => {}, obj, 'z', 'message'); + }); + + test('doesNotDecrease', () => { + const obj = { z: 3 }; + + assert.doesNotDecrease(() => {}, obj, 'z'); + assert.doesNotDecrease(() => {}, obj, 'z', 'message'); + }); + + test('ifError', () => { + const obj = { z: 3 }; + + assert.ifError(obj); + assert.ifError(obj, 'message'); + }); + + test('extensible', () => { + const obj = { z: 3 }; + + assert.extensible(obj); + assert.extensible(obj, 'message'); + }); + + test('isNotExtensible', () => { + const obj = { z: 3 }; + + assert.isNotExtensible(obj); + assert.isNotExtensible(obj, 'message'); + }); + + test('isSealed', () => { + const obj = { z: 3 }; + + assert.isSealed(obj); + assert.isSealed(obj, 'message'); + }); + + test('sealed', () => { + const obj = { z: 3 }; + + assert.sealed(obj); + assert.sealed(obj, 'message'); + }); + + test('isNotSealed', () => { + const obj = { z: 3 }; + + assert.isNotSealed(obj); + assert.isNotSealed(obj, 'message'); + }); + + test('notSealed', () => { + const obj = { z: 3 }; + + assert.notSealed(obj); + assert.notSealed(obj, 'message'); + }); + + test('isFrozen', () => { + const obj = { z: 3 }; + + assert.isFrozen(obj); + assert.isFrozen(obj, 'message'); + }); + + test('frozen', () => { + const obj = { z: 3 }; + + assert.frozen(obj); + assert.frozen(obj, 'message'); + }); + + test('isNotFrozen', () => { + const obj = { z: 3 }; + + assert.isNotFrozen(obj); + assert.isNotFrozen(obj, 'message'); + }); + + test('notFrozen', () => { + const obj = { z: 3 }; + + assert.notFrozen(obj); + assert.notFrozen(obj, 'message'); + }); +}); \ No newline at end of file diff --git a/types/chai/index.d.ts b/types/chai/index.d.ts index 532aa3b579..b349be0ac4 100644 --- a/types/chai/index.d.ts +++ b/types/chai/index.d.ts @@ -1,10 +1,11 @@ -// Type definitions for chai 3.4.0 +// Type definitions for chai 3.5.0 // Project: http://chaijs.com/ // Definitions by: Jed Mao , // Bart van der Schoor , // Andrew Brown , // Olivier Chevet , -// Matt Wistrand +// Matt Wistrand , +// Josh Goldberg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // @@ -17,14 +18,15 @@ declare namespace Chai { /** * Provides a way to extend the internals of Chai */ - use(fn: (chai: any, utils: any) => void): ChaiStatic; + use(fn: (chai: (any), utils: any) => void): ChaiStatic; assert: AssertStatic; config: Config; AssertionError: typeof AssertionError; + version: string; } export interface ExpectStatic extends AssertionStatic { - fail(actual?: any, expected?: any, message?: string, operator?: string): void; + fail(actual?: any, expected?: any, message?: string, operator?: Operator): void; } export interface AssertStatic extends Assert { @@ -34,6 +36,10 @@ declare namespace Chai { (target: any, message?: string): Assertion; } + export type Operator = string; // "==" | "===" | ">" | ">=" | "<" | "<=" | "!=" | "!=="; + + export type OperatorComparable = boolean | null | number | string | undefined | Date; + interface ShouldAssertion { equal(value1: any, value2: any, message?: string): void; Throw: ShouldThrow; @@ -43,7 +49,7 @@ declare namespace Chai { interface Should extends ShouldAssertion { not: ShouldAssertion; - fail(actual: any, expected: any, message?: string, operator?: string): void; + fail(actual: any, expected: any, message?: string, operator?: Operator): void; } interface ShouldThrow { @@ -238,146 +244,975 @@ declare namespace Chai { } interface PropertyChange { - (object: Object, prop: string, msg?: string): Assertion; + (object: Object, property: string, message?: string): Assertion; } export interface Assert { /** - * @param expression Expression to test for truthiness. - * @param message Message to display on error. + * @param expression Expression to test for truthiness. + * @param message Message to display on error. */ (expression: any, message?: string): void; - fail(actual?: any, expected?: any, msg?: string, operator?: string): void; + /** + * Throws a failure. + * + * @type T Type of the objects. + * @param actual Actual value. + * @param expected Potential expected value. + * @param message Message to display on error. + * @param operator Comparison operator, if not strict equality. + * @remarks Node.js assert module-compatible. + */ + fail(actual?: T, expected?: T, message?: string, operator?: Operator): void; - ok(val: any, msg?: string): void; - isOk(val: any, msg?: string): void; - notOk(val: any, msg?: string): void; - isNotOk(val: any, msg?: string): void; + /** + * Asserts that object is truthy. + * + * @type T Type of object. + * @param object Object to test. + * @param message Message to display on error. + */ + isOk(value: T, message?: string): void; - equal(act: any, exp: any, msg?: string): void; - notEqual(act: any, exp: any, msg?: string): void; + /** + * Asserts that object is truthy. + * + * @type T Type of object. + * @param object Object to test. + * @param message Message to display on error. + */ + ok(value: T, message?: string): void; - strictEqual(act: any, exp: any, msg?: string): void; - notStrictEqual(act: any, exp: any, msg?: string): void; + /** + * Asserts that object is falsy. + * + * @type T Type of object. + * @param object Object to test. + * @param message Message to display on error. + */ + isNotOk(value: T, message?: string): void; - deepEqual(act: any, exp: any, msg?: string): void; - notDeepEqual(act: any, exp: any, msg?: string): void; + /** + * Asserts that object is falsy. + * + * @type T Type of object. + * @param object Object to test. + * @param message Message to display on error. + */ + notOk(value: T, message?: string): void; - isTrue(val: any, msg?: string): void; - isFalse(val: any, msg?: string): void; + /** + * Asserts non-strict equality (==) of actual and expected. + * + * @type T Type of the objects. + * @param actual Actual value. + * @param expected Potential expected value. + * @param message Message to display on error. + */ + equal(actual: T, expected: T, message?: string): void; - isNotTrue(val: any, msg?: string): void; - isNotFalse(val: any, msg?: string): void; + /** + * Asserts non-strict inequality (==) of actual and expected. + * + * @type T Type of the objects. + * @param actual Actual value. + * @param expected Potential expected value. + * @param message Message to display on error. + */ + notEqual(actual: T, expected: T, message?: string): void; - isNull(val: any, msg?: string): void; - isNotNull(val: any, msg?: string): void; + /** + * Asserts strict equality (===) of actual and expected. + * + * @type T Type of the objects. + * @param actual Actual value. + * @param expected Potential expected value. + * @param message Message to display on error. + */ + strictEqual(actual: T, expected: T, message?: string): void; - isUndefined(val: any, msg?: string): void; - isDefined(val: any, msg?: string): void; + /** + * Asserts strict inequality (==) of actual and expected. + * + * @type T Type of the objects. + * @param actual Actual value. + * @param expected Potential expected value. + * @param message Message to display on error. + */ + notStrictEqual(actual: T, expected: T, message?: string): void; - isNaN(val: any, msg?: string): void; - isNotNaN(val: any, msg?: string): void; + /** + * Asserts that actual is deeply equal to expected. + * + * @type T Type of the objects. + * @param actual Actual value. + * @param expected Potential expected value. + * @param message Message to display on error. + */ + deepEqual(actual: T, expected: T, message?: string): void; - isAbove(val: number, abv: number, msg?: string): void; - isBelow(val: number, blw: number, msg?: string): void; + /** + * Asserts that actual is not deeply equal to expected. + * + * @type T Type of the objects. + * @param actual Actual value. + * @param expected Potential expected value. + * @param message Message to display on error. + */ + notDeepEqual(actual: T, expected: T, message?: string): void; - isAtLeast(val: number, atlst: number, msg?: string): void; - isAtMost(val: number, atmst: number, msg?: string): void; + /** + * Asserts valueToCheck is strictly greater than (>) valueToBeAbove. + * + * @param valueToCheck Actual value. + * @param valueToBeAbove Minimum Potential expected value. + * @param message Message to display on error. + */ + isAbove(valueToCheck: number, valueToBeAbove: number, message?: string): void; - isFunction(val: any, msg?: string): void; - isNotFunction(val: any, msg?: string): void; + /** + * Asserts valueToCheck is greater than or equal to (>=) valueToBeAtLeast. + * + * @param valueToCheck Actual value. + * @param valueToBeAtLeast Minimum Potential expected value. + * @param message Message to display on error. + */ + isAtLeast(valueToCheck: number, valueToBeAtLeast: number, message?: string): void; - isObject(val: any, msg?: string): void; - isNotObject(val: any, msg?: string): void; + /** + * Asserts valueToCheck is strictly less than (<) valueToBeBelow. + * + * @param valueToCheck Actual value. + * @param valueToBeBelow Minimum Potential expected value. + * @param message Message to display on error. + */ + isBelow(valueToCheck: number, valueToBeBelow: number, message?: string): void; - isArray(val: any, msg?: string): void; - isNotArray(val: any, msg?: string): void; + /** + * Asserts valueToCheck is greater than or equal to (>=) valueToBeAtMost. + * + * @param valueToCheck Actual value. + * @param valueToBeAtMost Minimum Potential expected value. + * @param message Message to display on error. + */ + isAtMost(valueToCheck: number, valueToBeAtMost: number, message?: string): void; - isString(val: any, msg?: string): void; - isNotString(val: any, msg?: string): void; + /** + * Asserts that value is true. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isTrue(value: T, message?: string): void; - isNumber(val: any, msg?: string): void; - isNotNumber(val: any, msg?: string): void; + /** + * Asserts that value is false. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isFalse(value: T, message?: string): void; - isBoolean(val: any, msg?: string): void; - isNotBoolean(val: any, msg?: string): void; + /** + * Asserts that value is not true. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotTrue(value: T, message?: string): void; - typeOf(val: any, type: string, msg?: string): void; - notTypeOf(val: any, type: string, msg?: string): void; + /** + * Asserts that value is not false. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotFalse(value: T, message?: string): void; - instanceOf(val: any, type: Function, msg?: string): void; - notInstanceOf(val: any, type: Function, msg?: string): void; + /** + * Asserts that value is null. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNull(value: T, message?: string): void; - include(exp: string, inc: any, msg?: string): void; - include(exp: any[], inc: any, msg?: string): void; + /** + * Asserts that value is not null. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotNull(value: T, message?: string): void; - notInclude(exp: string, inc: any, msg?: string): void; - notInclude(exp: any[], inc: any, msg?: string): void; + /** + * Asserts that value is not null. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNaN(value: T, message?: string): void; - match(exp: any, re: RegExp, msg?: string): void; - notMatch(exp: any, re: RegExp, msg?: string): void; + /** + * Asserts that value is not null. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotNaN(value: T, message?: string): void; - property(obj: Object, prop: string, msg?: string): void; - notProperty(obj: Object, prop: string, msg?: string): void; - deepProperty(obj: Object, prop: string, msg?: string): void; - notDeepProperty(obj: Object, prop: string, msg?: string): void; + /** + * Asserts that value is undefined. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isUndefined(value: T, message?: string): void; - propertyVal(obj: Object, prop: string, val: any, msg?: string): void; - propertyNotVal(obj: Object, prop: string, val: any, msg?: string): void; + /** + * Asserts that value is not undefined. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isDefined(value: T, message?: string): void; - deepPropertyVal(obj: Object, prop: string, val: any, msg?: string): void; - deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string): void; + /** + * Asserts that value is a function. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isFunction(value: T, message?: string): void; - lengthOf(exp: any, len: number, msg?: string): void; - //alias frenzy - throw(fn: Function, msg?: string): void; + /** + * Asserts that value is not a function. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotFunction(value: T, message?: string): void; + + /** + * Asserts that value is an object of type 'Object' + * (as revealed by Object.prototype.toString). + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + * @remarks The assertion does not match subclassed objects. + */ + isObject(value: T, message?: string): void; + + /** + * Asserts that value is not an object of type 'Object' + * (as revealed by Object.prototype.toString). + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotObject(value: T, message?: string): void; + + /** + * Asserts that value is an array. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isArray(value: T, message?: string): void; + + /** + * Asserts that value is not an array. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotArray(value: T, message?: string): void; + + /** + * Asserts that value is a string. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isString(value: T, message?: string): void; + + /** + * Asserts that value is not a string. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotString(value: T, message?: string): void; + + /** + * Asserts that value is a number. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNumber(value: T, message?: string): void; + + /** + * Asserts that value is not a number. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotNumber(value: T, message?: string): void; + + /** + * Asserts that value is a boolean. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isBoolean(value: T, message?: string): void; + + /** + * Asserts that value is not a boolean. + * + * @type T Type of value. + * @param value Actual value. + * @param message Message to display on error. + */ + isNotBoolean(value: T, message?: string): void; + + /** + * Asserts that value's type is name, as determined by Object.prototype.toString. + * + * @type T Type of value. + * @param value Actual value. + * @param name Potential expected type name of value. + * @param message Message to display on error. + */ + typeOf(value: T, name: string, message?: string): void; + + /** + * Asserts that value's type is not name, as determined by Object.prototype.toString. + * + * @type T Type of value. + * @param value Actual value. + * @param name Potential expected type name of value. + * @param message Message to display on error. + */ + notTypeOf(value: T, name: string, message?: string): void; + + /** + * Asserts that value is an instance of constructor. + * + * @type T Type of value. + * @param value Actual value. + * @param constructor Potential expected contructor of value. + * @param message Message to display on error. + */ + instanceOf(value: T, constructor: Function, message?: string): void; + + /** + * Asserts that value is not an instance of constructor. + * + * @type T Type of value. + * @param value Actual value. + * @param constructor Potential expected contructor of value. + * @param message Message to display on error. + */ + notInstanceOf(value: T, type: Function, message?: string): void; + + /** + * Asserts that haystack includes needle. + * + * @param haystack Container string. + * @param needle Potential expected substring of haystack. + * @param message Message to display on error. + */ + include(haystack: string, needle: string, message?: string): void; + + /** + * Asserts that haystack includes needle. + * + * @type T Type of values in haystack. + * @param haystack Container array. + * @param needle Potential value contained in haystack. + * @param message Message to display on error. + */ + include(haystack: T[], needle: T, message?: string): void; + + /** + * Asserts that haystack does not include needle. + * + * @param haystack Container string. + * @param needle Potential expected substring of haystack. + * @param message Message to display on error. + */ + notInclude(haystack: string, needle: any, message?: string): void; + + /** + * Asserts that haystack does not include needle. + * + * @type T Type of values in haystack. + * @param haystack Container array. + * @param needle Potential value contained in haystack. + * @param message Message to display on error. + */ + notInclude(haystack: any[], needle: any, message?: string): void; + + /** + * Asserts that value matches the regular expression regexp. + * + * @param value Actual value. + * @param regexp Potential match of value. + * @param message Message to display on error. + */ + match(value: string, regexp: RegExp, message?: string): void; + + /** + * Asserts that value does not match the regular expression regexp. + * + * @param value Actual value. + * @param regexp Potential match of value. + * @param message Message to display on error. + */ + notMatch(expected: any, regexp: RegExp, message?: string): void; + + /** + * Asserts that object has a property named by property. + * + * @type T Type of object. + * @param object Container object. + * @param property Potential contained property of object. + * @param message Message to display on error. + */ + property(object: T, property: keyof T, message?: string): void; + + /** + * Asserts that object has a property named by property. + * + * @type T Type of object. + * @param object Container object. + * @param property Potential contained property of object. + * @param message Message to display on error. + */ + notProperty(object: T, property: keyof T, message?: string): void; + + /** + * Asserts that object has a property named by property, which can be a string + * using dot- and bracket-notation for deep reference. + * + * @type T Type of object. + * @param object Container object. + * @param property Potential contained property of object. + * @param message Message to display on error. + */ + deepProperty(object: T, property: string, message?: string): void; + + /** + * Asserts that object does not have a property named by property, which can be a + * string using dot- and bracket-notation for deep reference. + * + * @type T Type of object. + * @param object Container object. + * @param property Potential contained property of object. + * @param message Message to display on error. + */ + notDeepProperty(object: T, property: string, message?: string): void; + + /** + * Asserts that object has a property named by property with value given by value. + * + * @type T Type of object. + * @type V Type of value. + * @param object Container object. + * @param property Potential contained property of object. + * @param value Potential expected property value. + * @param message Message to display on error. + */ + propertyVal(object: T, property: keyof T, value: V, message?: string): void; + + /** + * Asserts that object has a property named by property with value given by value. + * + * @type T Type of object. + * @type V Type of value. + * @param object Container object. + * @param property Potential contained property of object. + * @param value Potential expected property value. + * @param message Message to display on error. + */ + propertyNotVal(object: T, property: keyof T, value: V, message?: string): void; + + /** + * Asserts that object has a property named by property, which can be a string + * using dot- and bracket-notation for deep reference. + * + * @type T Type of object. + * @type V Type of value. + * @param object Container object. + * @param property Potential contained property of object. + * @param value Potential expected property value. + * @param message Message to display on error. + */ + deepPropertyVal(object: T, property: string, value: V, message?: string): void; + + /** + * Asserts that object does not have a property named by property, which can be a + * string using dot- and bracket-notation for deep reference. + * + * @type T Type of object. + * @type V Type of value. + * @param object Container object. + * @param property Potential contained property of object. + * @param value Potential expected property value. + * @param message Message to display on error. + */ + deepPropertyNotVal(object: T, property: string, value: T, message?: string): void; + + /** + * Asserts that object has a length property with the expected value. + * + * @type T Type of object. + * @param object Container object. + * @param length Potential expected length of object. + * @param message Message to display on error. + */ + lengthOf(object: T, length: number, message?: string): void; + + /** + * Asserts that fn will throw an error. + * + * @param fn Function that may throw. + * @param message Message to display on error. + */ + throw(fn: Function, message?: string): void; + + /** + * Asserts that function will throw an error with message matching regexp. + * + * @param fn Function that may throw. + * @param regExp Potential expected message match. + * @param message Message to display on error. + */ throw(fn: Function, regExp: RegExp): void; - throw(fn: Function, errType: Function, msg?: string): void; - throw(fn: Function, errType: Function, regExp: RegExp): void; - throws(fn: Function, msg?: string): void; + /** + * Asserts that function will throw an error that is an instance of constructor. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ + throw(fn: Function, constructor: Function, message?: string): void; + + /** + * Asserts that function will throw an error that is an instance of constructor + * and an error with message matching regexp. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ + throw(fn: Function, constructor: Function, regExp: RegExp): void; + + /** + * Asserts that fn will throw an error. + * + * @param fn Function that may throw. + * @param message Message to display on error. + */ + throws(fn: Function, message?: string): void; + + /** + * Asserts that function will throw an error with message matching regexp. + * + * @param fn Function that may throw. + * @param regExp Potential expected message match. + * @param message Message to display on error. + */ throws(fn: Function, regExp: RegExp): void; - throws(fn: Function, errType: Function, msg?: string): void; + + /** + * Asserts that function will throw an error that is an instance of constructor. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ + throws(fn: Function, errType: Function, message?: string): void; + + /** + * Asserts that function will throw an error that is an instance of constructor + * and an error with message matching regexp. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ throws(fn: Function, errType: Function, regExp: RegExp): void; - Throw(fn: Function, msg?: string): void; + /** + * Asserts that fn will throw an error. + * + * @param fn Function that may throw. + * @param message Message to display on error. + */ + Throw(fn: Function, message?: string): void; + + /** + * Asserts that function will throw an error with message matching regexp. + * + * @param fn Function that may throw. + * @param regExp Potential expected message match. + * @param message Message to display on error. + */ Throw(fn: Function, regExp: RegExp): void; - Throw(fn: Function, errType: Function, msg?: string): void; + + /** + * Asserts that function will throw an error that is an instance of constructor. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ + Throw(fn: Function, errType: Function, message?: string): void; + + /** + * Asserts that function will throw an error that is an instance of constructor + * and an error with message matching regexp. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ Throw(fn: Function, errType: Function, regExp: RegExp): void; - doesNotThrow(fn: Function, msg?: string): void; + /** + * Asserts that fn will not throw an error. + * + * @param fn Function that may throw. + * @param message Message to display on error. + */ + doesNotThrow(fn: Function, message?: string): void; + + /** + * Asserts that function will throw an error with message matching regexp. + * + * @param fn Function that may throw. + * @param regExp Potential expected message match. + * @param message Message to display on error. + */ doesNotThrow(fn: Function, regExp: RegExp): void; - doesNotThrow(fn: Function, errType: Function, msg?: string): void; + + /** + * Asserts that function will throw an error that is an instance of constructor. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ + doesNotThrow(fn: Function, errType: Function, message?: string): void; + + /** + * Asserts that function will throw an error that is an instance of constructor + * and an error with message matching regexp. + * + * @param fn Function that may throw. + * @param constructor Potential expected error constructor. + * @param message Message to display on error. + */ doesNotThrow(fn: Function, errType: Function, regExp: RegExp): void; - operator(val: any, operator: string, val2: any, msg?: string): void; - closeTo(act: number, exp: number, delta: number, msg?: string): void; - approximately(act: number, exp: number, delta: number, msg?: string): void; + /** + * Compares two values using operator. + * + * @param val1 Left value during comparison. + * @param operator Comparison operator. + * @param val2 Right value during comparison. + * @param message Message to display on error. + */ + operator(val1: OperatorComparable, operator: Operator, val2: OperatorComparable, message?: string): void; - sameMembers(set1: any[], set2: any[], msg?: string): void; - sameDeepMembers(set1: any[], set2: any[], msg?: string): void; - includeMembers(superset: any[], subset: any[], msg?: string): void; - includeDeepMembers(superset: any[], subset: any[], msg?: string): void; + /** + * Asserts that the target is equal to expected, to within a +/- delta range. + * + * @param actual Actual value + * @param expected Potential expected value. + * @param delta Maximum differenced between values. + * @param message Message to display on error. + */ + closeTo(actual: number, expected: number, delta: number, message?: string): void; - ifError(val: any, msg?: string): void; + /** + * Asserts that the target is equal to expected, to within a +/- delta range. + * + * @param actual Actual value + * @param expected Potential expected value. + * @param delta Maximum differenced between values. + * @param message Message to display on error. + */ + approximately(act: number, exp: number, delta: number, message?: string): void; - isExtensible(obj: {}, msg?: string): void; - extensible(obj: {}, msg?: string): void; - isNotExtensible(obj: {}, msg?: string): void; - notExtensible(obj: {}, msg?: string): void; + /** + * Asserts that set1 and set2 have the same members. Order is not take into account. + * + * @type T Type of set values. + * @param set1 Actual set of values. + * @param set2 Potential expected set of values. + * @param message Message to display on error. + */ + sameMembers(set1: T[], set2: T[], message?: string): void; - isSealed(obj: {}, msg?: string): void; - sealed(obj: {}, msg?: string): void; - isNotSealed(obj: {}, msg?: string): void; - notSealed(obj: {}, msg?: string): void; + /** + * Asserts that set1 and set2 have the same members using deep equality checking. + * Order is not take into account. + * + * @type T Type of set values. + * @param set1 Actual set of values. + * @param set2 Potential expected set of values. + * @param message Message to display on error. + */ + sameDeepMembers(set1: T[], set2: T[], message?: string): void; - isFrozen(obj: Object, msg?: string): void; - frozen(obj: Object, msg?: string): void; - isNotFrozen(obj: Object, msg?: string): void; - notFrozen(obj: Object, msg?: string): void; + /** + * Asserts that subset is included in superset. Order is not take into account. + * + * @type T Type of set values. + * @param superset Actual set of values. + * @param subset Potential contained set of values. + * @param message Message to display on error. + */ + includeMembers(superset: T[], subset: T[], message?: string): void; - oneOf(inList: any, list: any[], msg?: string): void; + /** + * Asserts that subset is included in superset using deep equality checking. + * Order is not take into account. + * + * @type T Type of set values. + * @param superset Actual set of values. + * @param subset Potential contained set of values. + * @param message Message to display on error. + */ + includeDeepMembers(superset: T[], subset: T[], message?: string): void; + + /** + * Asserts that non-object, non-array value inList appears in the flat array list. + * + * @type T Type of list values. + * @param inList Value expected to be in the list. + * @param list List of values. + * @param message Message to display on error. + */ + oneOf(inList: T, list: T[], message?: string): void; + + /** + * Asserts that a function changes the value of a property. + * + * @type T Type of object. + * @param modifier Function to run. + * @param object Container object. + * @param property Property of object expected to be modified. + * @param message Message to display on error. + */ + changes(modifier: Function, object: T, property: keyof T, message?: string): void + + /** + * Asserts that a function does not change the value of a property. + * + * @type T Type of object. + * @param modifier Function to run. + * @param object Container object. + * @param property Property of object expected not to be modified. + * @param message Message to display on error. + */ + doesNotChange(modifier: Function, object: T, property: keyof T, message?: string): void + + /** + * Asserts that a function increases an object property. + * + * @type T Type of object. + * @param modifier Function to run. + * @param object Container object. + * @param property Property of object expected to be increased. + * @param message Message to display on error. + */ + increases(modifier: Function, object: T, property: keyof T, message?: string): void + + /** + * Asserts that a function does not increase an object property. + * + * @type T Type of object. + * @param modifier Function to run. + * @param object Container object. + * @param property Property of object expected not to be increased. + * @param message Message to display on error. + */ + doesNotIncrease(modifier: Function, object: T, property: keyof T, message?: string): void + + /** + * Asserts that a function decreases an object property. + * + * @type T Type of object. + * @param modifier Function to run. + * @param object Container object. + * @param property Property of object expected to be decreased. + * @param message Message to display on error. + */ + decreases(modifier: Function, object: T, property: keyof T, message?: string): void + + /** + * Asserts that a function does not decrease an object property. + * + * @type T Type of object. + * @param modifier Function to run. + * @param object Container object. + * @param property Property of object expected not to be decreased. + * @param message Message to display on error. + */ + doesNotDecrease(modifier: Function, object: T, property: keyof T, message?: string): void + + /** + * Asserts if value is not a false value, and throws if it is a true value. + * + * @type T Type of object. + * @param object Actual value. + * @param message Message to display on error. + * @remarks This is added to allow for chai to be a drop-in replacement for + * Node’s assert class. + */ + ifError(object: T, message?: string): void; + + /** + * Asserts that object is extensible (can have new properties added to it). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + isExtensible(object: T, message?: string): void; + + /** + * Asserts that object is extensible (can have new properties added to it). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + extensible(object: T, message?: string): void; + + /** + * Asserts that object is not extensible. + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + isNotExtensible(object: T, message?: string): void; + + /** + * Asserts that object is not extensible. + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + notExtensible(object: T, message?: string): void; + + /** + * Asserts that object is sealed (can have new properties added to it + * and its existing properties cannot be removed). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + isSealed(object: T, message?: string): void; + + /** + * Asserts that object is sealed (can have new properties added to it + * and its existing properties cannot be removed). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + sealed(object: T, message?: string): void; + + /** + * Asserts that object is not sealed. + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + isNotSealed(object: T, message?: string): void; + + /** + * Asserts that object is not sealed. + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + notSealed(object: T, message?: string): void; + + /** + * Asserts that object is frozen (cannot have new properties added to it + * and its existing properties cannot be removed). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + isFrozen(object: T, message?: string): void; + + /** + * Asserts that object is frozen (cannot have new properties added to it + * and its existing properties cannot be removed). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + frozen(object: T, message?: string): void; + + /** + * Asserts that object is not frozen (cannot have new properties added to it + * and its existing properties cannot be removed). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + isNotFrozen(object: T, message?: string): void; + + /** + * Asserts that object is not frozen (cannot have new properties added to it + * and its existing properties cannot be removed). + * + * @type T Type of object + * @param object Actual value. + * @param message Message to display on error. + */ + notFrozen(object: T, message?: string): void; } export interface Config { @@ -406,7 +1241,7 @@ declare namespace Chai { } } -declare var chai: Chai.ChaiStatic; +declare const chai: Chai.ChaiStatic; declare module "chai" { export = chai; @@ -414,4 +1249,4 @@ declare module "chai" { interface Object { should: Chai.Assertion; -} +} \ No newline at end of file From 4318786e2f26ff2ffee815faa68b4b9714b1a2fa Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 5 Apr 2017 19:06:13 -0700 Subject: [PATCH 2/3] Commented out keyof types in chai They're also not TS 2 compatible... --- types/chai/index.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/types/chai/index.d.ts b/types/chai/index.d.ts index b349be0ac4..7444f5fd10 100644 --- a/types/chai/index.d.ts +++ b/types/chai/index.d.ts @@ -703,7 +703,7 @@ declare namespace Chai { * @param property Potential contained property of object. * @param message Message to display on error. */ - property(object: T, property: keyof T, message?: string): void; + property(object: T, property: string /* keyof T */, message?: string): void; /** * Asserts that object has a property named by property. @@ -713,7 +713,7 @@ declare namespace Chai { * @param property Potential contained property of object. * @param message Message to display on error. */ - notProperty(object: T, property: keyof T, message?: string): void; + notProperty(object: T, property: string /* keyof T */, message?: string): void; /** * Asserts that object has a property named by property, which can be a string @@ -747,7 +747,7 @@ declare namespace Chai { * @param value Potential expected property value. * @param message Message to display on error. */ - propertyVal(object: T, property: keyof T, value: V, message?: string): void; + propertyVal(object: T, property: string /* keyof T */, value: V, message?: string): void; /** * Asserts that object has a property named by property with value given by value. @@ -759,7 +759,7 @@ declare namespace Chai { * @param value Potential expected property value. * @param message Message to display on error. */ - propertyNotVal(object: T, property: keyof T, value: V, message?: string): void; + propertyNotVal(object: T, property: string /* keyof T */, value: V, message?: string): void; /** * Asserts that object has a property named by property, which can be a string @@ -1032,7 +1032,7 @@ declare namespace Chai { * @param property Property of object expected to be modified. * @param message Message to display on error. */ - changes(modifier: Function, object: T, property: keyof T, message?: string): void + changes(modifier: Function, object: T, property: string /* keyof T */, message?: string): void /** * Asserts that a function does not change the value of a property. @@ -1043,7 +1043,7 @@ declare namespace Chai { * @param property Property of object expected not to be modified. * @param message Message to display on error. */ - doesNotChange(modifier: Function, object: T, property: keyof T, message?: string): void + doesNotChange(modifier: Function, object: T, property: string /* keyof T */, message?: string): void /** * Asserts that a function increases an object property. @@ -1054,7 +1054,7 @@ declare namespace Chai { * @param property Property of object expected to be increased. * @param message Message to display on error. */ - increases(modifier: Function, object: T, property: keyof T, message?: string): void + increases(modifier: Function, object: T, property: string /* keyof T */, message?: string): void /** * Asserts that a function does not increase an object property. @@ -1065,7 +1065,7 @@ declare namespace Chai { * @param property Property of object expected not to be increased. * @param message Message to display on error. */ - doesNotIncrease(modifier: Function, object: T, property: keyof T, message?: string): void + doesNotIncrease(modifier: Function, object: T, property: string /* keyof T */, message?: string): void /** * Asserts that a function decreases an object property. @@ -1076,7 +1076,7 @@ declare namespace Chai { * @param property Property of object expected to be decreased. * @param message Message to display on error. */ - decreases(modifier: Function, object: T, property: keyof T, message?: string): void + decreases(modifier: Function, object: T, property: string /* keyof T */, message?: string): void /** * Asserts that a function does not decrease an object property. @@ -1087,7 +1087,7 @@ declare namespace Chai { * @param property Property of object expected not to be decreased. * @param message Message to display on error. */ - doesNotDecrease(modifier: Function, object: T, property: keyof T, message?: string): void + doesNotDecrease(modifier: Function, object: T, property: string /* keyof T */, message?: string): void /** * Asserts if value is not a false value, and throws if it is a true value. From 40354debb1db20dd93f52ffe6394bb5a310109a1 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 6 Apr 2017 09:13:07 -0700 Subject: [PATCH 3/3] Addressed small PR feedback Added back EOF endline; removed unnecessary parenthesis. --- types/chai/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/chai/index.d.ts b/types/chai/index.d.ts index 7444f5fd10..a040c43249 100644 --- a/types/chai/index.d.ts +++ b/types/chai/index.d.ts @@ -18,7 +18,7 @@ declare namespace Chai { /** * Provides a way to extend the internals of Chai */ - use(fn: (chai: (any), utils: any) => void): ChaiStatic; + use(fn: (chai: any, utils: any) => void): ChaiStatic; assert: AssertStatic; config: Config; AssertionError: typeof AssertionError; @@ -1249,4 +1249,4 @@ declare module "chai" { interface Object { should: Chai.Assertion; -} \ No newline at end of file +}