From 304b88f2be67579cd4c7ddce8ebf5be984bf9ddb Mon Sep 17 00:00:00 2001 From: Bartvds Date: Tue, 21 May 2013 16:39:25 +0200 Subject: [PATCH 1/2] Added definitions for jasmine-matchers --- jasmine-matchers/jasmine-matchers-tests.ts | 678 +++++++++++++++++++++ jasmine-matchers/jasmine-matchers.d.ts | 69 +++ 2 files changed, 747 insertions(+) create mode 100644 jasmine-matchers/jasmine-matchers-tests.ts create mode 100644 jasmine-matchers/jasmine-matchers.d.ts diff --git a/jasmine-matchers/jasmine-matchers-tests.ts b/jasmine-matchers/jasmine-matchers-tests.ts new file mode 100644 index 000000000..d1cbc0f90 --- /dev/null +++ b/jasmine-matchers/jasmine-matchers-tests.ts @@ -0,0 +1,678 @@ +/* +Typings 2013 Bart van der Schoor + +TypeScript tests auto-extracted from jasmine-matchers unit test. + +Original jasmine-matchers license applies: + +Copyright (C) 2013, uxebu Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/// +/// + +describe('toBeArray', function () { + describe('matches', function () { + it('should pass for []', function () { + expect([]).toBeArray(); + }); + it('should pass for `new Array`', function () { + expect(new Array()).toBeArray(); + }); + it('should pass for [1,"",{}]', function () { + expect([ + 1, + "", + { + } + ]).toBeArray(); + }); + }); + describe('.not matches', function () { + it('should pass for {}', function () { + expect({ + }).not.toBeArray(); + }); + it('should pass for `arguments`', function () { + expect(arguments).not.toBeArray(); + }); + }); +}); +describe('toBeNumber', function () { + describe('matches', function () { + it('should pass for 0', function () { + expect(0).toBeNumber(); + }); + it('should pass for 2.1', function () { + expect(2.1).toBeNumber(); + }); + }); + describe('non matches', function () { + it('should pass for "x"', function () { + expect('x').not.toBeNumber(); + }); + it('should pass for function(){}', function () { + expect(function () { + }).not.toBeNumber(); + }); + }); +}); +describe('toBeInstanceOf', function () { + describe('matches', function () { + it('should work for `function(){}` to be instance of `Function`', function () { + expect(function () { + }).toBeInstanceOf(Function); + }); + }); +}); +describe('toBeNan', function () { + describe('matches', function () { + it('should work for NaN', function () { + expect(NaN).toBeNan(); + }); + }); +}); +describe('toBeOfType', function () { + describe('matches', function () { + it('should work for `number`', function () { + expect(1).toBeOfType('number'); + }); + }); + describe('non-matches', function () { + it('should work for `number`', function () { + expect('a').not.toBeOfType('number'); + }); + }); +}); +describe('toBeInRange', function () { + describe('matches', function () { + it('should find 0 in 0..1', function () { + expect(0).toBeInRange(0, 1); + }); + it('should find 1 in 0..2', function () { + expect(1).toBeInRange(0, 2); + }); + it('should find 1.5 in 1..2', function () { + expect(1.5).toBeInRange(1, 2); + }); + }); + describe('non-matches', function () { + it('should not find 0 in 1..2', function () { + expect(0).not.toBeInRange(1, 2); + }); + it('should not find 100 in 33..55', function () { + expect(100).not.toBeInRange(33, 55); + }); + }); +}); +describe('toBeOneOf', function () { + describe('matches', function () { + it('should find "a" in ["a", "b"]', function () { + expect('a').toBeOneOf([ + 'a', + 'b' + ]); + }); + it('should find "uxebu" in ["company", "uxebu"]', function () { + expect('uxebu').toBeOneOf([ + 'company', + 'uxebu' + ]); + }); + }); + describe('non-matches', function () { + it('should not find "" in [" ", "0"]', function () { + expect('').not.toBeOneOf([ + ' ', + '0' + ]); + }); + it('should not find "a" in ["b", "c"]', function () { + expect('a').not.toBeOneOf([ + 'b', + 'c' + ]); + }); + }); +}); +describe('toBeCloseToOneOf', function () { + function oneDigitOff(actual, expected) { + var actualInt = parseInt(actual, 10); + return actualInt - 1 <= expected && actualInt + 1 >= expected; + } + function tenPercentOff(actual, expected) { + return expected * 0.9 <= actual && expected * 1.1 >= actual; + } + function oneDigitOrTenPercentOff(actual, expected) { + return oneDigitOff(actual, expected) || tenPercentOff(actual, expected); + } + function twoDecimalsOff(actual, expected) { + var lower = ((expected * 100) - 2) / 100; + var upper = ((expected * 100) + 2) / 100; + return lower <= actual && upper >= actual; + } + describe('matches', function () { + it('should say 7 is close to one of [8, 9]', function () { + expect(7).toBeCloseToOneOf([ + 8, + 9 + ], oneDigitOff); + }); + it('should say 2 is 10% off of one of [2.2, 1.0]', function () { + expect(2).toBeCloseToOneOf([ + 2.2, + 1.0 + ], tenPercentOff); + }); + it('should say 7 is close to one of [8, 9]', function () { + expect(7).toBeCloseToOneOf([ + 8, + 9 + ], oneDigitOrTenPercentOff); + }); + it('should say 1.345 two decimals off of [1.325, 1.365]', function () { + expect(1.345).toBeCloseToOneOf([ + 1.325, + 1.365 + ], twoDecimalsOff); + }); + }); + describe('non-matches', function () { + it('should say 7 is NOT one off of [9, 10, 11]', function () { + expect(7).not.toBeCloseToOneOf([ + 9, + 10, + 11 + ], oneDigitOff); + }); + it('should say 1 is close to one of [8, 9]', function () { + expect(1).not.toBeCloseToOneOf([ + 8, + 9 + ], oneDigitOrTenPercentOff); + }); + it('should say 1.9 is NOT 10% off of one of [2.2, 1.0]', function () { + expect(1.9).not.toBeCloseToOneOf([ + 2.2, + 1.0 + ], tenPercentOff); + }); + it('should say 1.345 two decimals off of [1.325, 1.365]', function () { + expect(1.304).not.toBeCloseToOneOf([ + 1.325, + 1.365 + ], twoDecimalsOff); + }); + }); +}); + +describe('toContainOnce', function () { + describe('matches', function () { + it('should work for arrays', function () { + expect([ + 1, + 2 + ]).toContainOnce(1); + }); + it('should work for strings', function () { + expect('uxebu rox').toContainOnce('uxebu'); + }); + }); + describe('non-matches', function () { + it('should work for arrays', function () { + expect([ + 1, + 2 + ]).not.toContainOnce(3); + }); + it('should work for strings', function () { + expect('uxebu rox').not.toContainOnce('u'); + }); + it('should work for undefined', function () { + expect(undefined).not.toContainOnce(1); + }); + }); +}); + +describe('toHaveLength', function () { + describe('matches', function () { + it('should work for `{length:2}`', function () { + expect({ + length: 2 + }).toHaveLength(2); + }); + it('should work for `{length:null}`', function () { + expect({ + length: null + }).toHaveLength(null); + }); + }); +}); +describe('toHaveProperties', function () { + describe('matches', function () { + it('should work for `{x:0, y:undefined}`', function () { + var obj = { + x: 0, + y: undefined + }; + expect(obj).toHaveProperties('x', 'y'); + }); + }); +}); +describe('toHavePropertiesWithValues', function () { + describe('matches', function () { + it('should work with a reference object', function () { + function C() { + this.x = 0; + } + C.prototype.y = 'arbitrary'; + expect(new C()).toHavePropertiesWithValues({ + x: 0, + y: 'arbitrary', + constructor: C + }); + }); + }); +}); +describe('toHaveOwnProperties', function () { + describe('matches', function () { + it('should work for `{x:0, y:undefined}`', function () { + var obj = { + x: 0, + y: undefined + }; + expect(obj).toHaveOwnProperties('x', 'y'); + }); + }); +}); +describe('toHaveOwnPropertiesWithValues', function () { + describe('matches', function () { + it('should work with a reference object', function () { + expect({ + x: 0, + y: 'arbitrary' + }).toHaveOwnPropertiesWithValues({ + x: 0, + y: 'arbitrary' + }); + }); + }); +}); +describe('toHaveBeenCalledXTimes', function () { + describe('matches', function () { + it('should work for 1', function () { + var func = jasmine.createSpy('func'); + func(); + expect(func).toHaveBeenCalledXTimes(1); + }); + it('should work for 2', function () { + var func = jasmine.createSpy('func'); + func(); + func(); + expect(func).not.toHaveBeenCalledXTimes(1); + }); + }); +}); +describe('toExactlyHaveProperties', function () { + describe('matches', function () { + it('should work for `{x:0, y:undefined}`', function () { + var obj = { + x: 0, + y: undefined + }; + expect(obj).toExactlyHaveProperties('x', 'y'); + }); + it('should work in any order', function () { + var obj = { + x: 0, + y: undefined + }; + expect(obj).toExactlyHaveProperties('y', 'x'); + }); + }); + describe('non-matches', function () { + it('should work for too many properties', function () { + var obj = { + x: 0, + y: undefined + }; + expect(obj).not.toExactlyHaveProperties('x'); + }); + it('should work for missing properties', function () { + var obj = { + x: 0, + y: undefined + }; + expect(obj).not.toExactlyHaveProperties('x', 'y', 'z'); + }); + }); +}); + +describe('toEndWith', function () { + describe('matches', function () { + it('should work for string', function () { + expect('abc').toEndWith('c'); + }); + it('should work for equal string', function () { + expect('abc').toEndWith('abc'); + }); + }); + describe('non-matches', function () { + it('should work for string', function () { + expect('abc').not.toEndWith('d'); + }); + it('should work for equal string', function () { + expect('abc').not.toEndWith('abz'); + }); + }); + describe('with array', function () { + describe('matches', function () { + it('should work for string', function () { + expect([ + '1', + '2' + ]).toEndWith('2'); + }); + it('should work for array', function () { + expect([ + 3, + 4, + 5 + ]).toEndWith([ + 4, + 5 + ]); + }); + }); + describe('non-matches', function () { + it('should work for string', function () { + expect([ + '1', + '2' + ]).not.toEndWith('3'); + }); + it('should work for array', function () { + expect([ + 3, + 4, + 5 + ]).not.toEndWith([ + 3, + 4 + ]); + }); + }); + }); +}); +describe('toEachEndWith', function () { + describe('matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).toEachEndWith('e'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'zwee', + 'three' + ]).toEachEndWith('e'); + }); + }); + describe('non-matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).not.toEachEndWith('o'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'zwei', + 'three' + ]).not.toEachEndWith('e'); + }); + }); +}); +describe('toSomeEndWith', function () { + describe('matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).toSomeEndWith('e'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'zwee', + 'three' + ]).toSomeEndWith('ee'); + }); + }); + describe('non-matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).not.toSomeEndWith('o'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'zwei', + 'three' + ]).not.toSomeEndWith('a'); + }); + }); +}); +describe('toStartWith', function () { + describe('matches', function () { + it('should work for string', function () { + expect('abc').toStartWith('a'); + }); + it('should work for equal string', function () { + expect('abc').toStartWith('abc'); + }); + }); + describe('non-matches', function () { + it('should work for string', function () { + expect('abc').not.toStartWith('d'); + }); + it('should work for equal string', function () { + expect('abc').not.toStartWith('abz'); + }); + }); + describe('with array', function () { + describe('matches', function () { + it('should work for string', function () { + expect([ + '1', + '2' + ]).toStartWith('1'); + }); + it('should work for array', function () { + expect([ + 3, + 4, + 5 + ]).toStartWith([ + 3, + 4 + ]); + }); + }); + describe('non-matches', function () { + it('should work for string', function () { + expect([ + '1', + '2' + ]).not.toStartWith('3'); + }); + it('should work for array', function () { + expect([ + 3, + 4, + 5 + ]).not.toStartWith([ + 4, + 5 + ]); + }); + }); + }); +}); +describe('toEachStartWith', function () { + describe('matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).toEachStartWith('o'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'onetwo', + 'onethree' + ]).toEachStartWith('o'); + }); + }); + describe('non-matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).not.toEachStartWith('e'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'two', + 'onethree' + ]).not.toEachStartWith('o'); + }); + }); +}); +describe('toSomeStartWith', function () { + describe('matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).toSomeStartWith('o'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'onetwo', + 'three' + ]).toSomeStartWith('one'); + }); + }); + describe('non-matches', function () { + it('should work for array with one element', function () { + expect([ + 'one' + ]).not.toSomeStartWith('e'); + }); + it('should work for array with multiple elements', function () { + expect([ + 'one', + 'two', + 'onethree' + ]).not.toSomeStartWith('a'); + }); + }); +}); +describe('toStartWithEither', function () { + describe('matches', function () { + it('should work for two parameters', function () { + expect('one').toStartWithEither('two', 'one'); + }); + it('should work for three parameters', function () { + expect('one').toStartWithEither('two', 'one', 'three'); + }); + it('should work for multiple matches', function () { + expect('one').toStartWithEither('on', 'one', 'o'); + }); + }); + describe('non-matches', function () { + it('should work for two elements', function () { + expect('one').not.toStartWithEither('e', 'a'); + }); + it('should work for three elements', function () { + expect('one').not.toStartWithEither('ne', 'ones', 'two'); + }); + }); + describe('with array', function () { + describe('matches', function () { + it('should work for string', function () { + expect([ + '1', + '2' + ]).toStartWithEither('1', '2'); + }); + it('should work for array', function () { + expect([ + 3, + 4, + 5 + ]).toStartWithEither([ + 4 + ], [ + 3, + 4 + ]); + }); + }); + describe('non-matches', function () { + it('should work for string', function () { + expect([ + '1', + '2' + ]).not.toStartWithEither('3'); + }); + it('should work for array', function () { + expect([ + 3, + 4, + 5 + ]).not.toStartWithEither([ + 5, + 6 + ], [ + 4, + 5 + ]); + }); + }); + }); +}); + +describe('toThrowInstanceOf', function () { + describe('matches', function () { + it('should work for `Error`', function () { + expect(function () { + throw new Error(); + }).toThrowInstanceOf(Error); + }); + }); +}); +describe('toThrowStartsWith', function () { + describe('matches', function () { + it('should match the error string', function () { + expect(function () { + throw new Error('ooops'); + }).toThrowStartsWith('ooops'); + }); + }); + describe('non-matches', function () { + it('should mismatch the error string', function () { + expect(function () { + throw new Error('ooops'); + }).not.toThrowStartsWith('1'); + }); + }); +}); diff --git a/jasmine-matchers/jasmine-matchers.d.ts b/jasmine-matchers/jasmine-matchers.d.ts new file mode 100644 index 000000000..ed516bdb7 --- /dev/null +++ b/jasmine-matchers/jasmine-matchers.d.ts @@ -0,0 +1,69 @@ +// Type definitions for jasmine-matchers v0.2.1 API +// Project: https://github.com/uxebu/jasmine-matchers +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/* +Typings 2013 Bart van der Schoor + +TypeScript tests auto-extracted from jasmine-matchers unit test. + +Original jasmine-matchers license applies: + +Copyright (C) 2013, uxebu Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/// + +declare module jasmine { + interface Matchers { + + //toBe + toBeArray(): bool; + toBeCloseToOneOf(values: any[], isCloseToFunction: (actual: number, expected: number) => bool): bool; + toBeInstanceOf(Constructor: Function): bool; + toBeInRange(min: number, max: number): bool; + toBeNan(): bool; + toBeNumber(): bool; + toBeOfType(type: string): bool; + toBeOneOf(values: any[]): bool; + + //toContain + toContainOnce(value: any): bool; + + //toHave + toHaveBeenCalledXTimes(count:number): bool; + toHaveLength(length:number): bool; + toHaveOwnProperties(...names:string[]): bool; + toHaveOwnPropertiesWithValues(obj:Object): bool; + toHaveProperties(...names:string[]): bool; + toHavePropertiesWithValues(obj:Object): bool; + toExactlyHaveProperties(...names:string[]): bool; + + //toStartEndWith + toStartWith(value:any): bool; + toStartWith(value:any[]): bool; + + toEndWith(value:any): bool; + toEndWith(values:any[]): bool; + + toEachStartWith(searchString:string): bool; + toSomeStartWith(searchString:string): bool; + + toEachEndWith(searchString:string): bool; + toSomeEndWith(searchString:string): bool; + + toStartWithEither(...searchString:any[]): bool; + + //toThrow + toThrowInstanceOf(klass:Function): bool; + toThrowStartsWith(text:string): bool; + } +} + From 084a51a992ea50fe8262348f25ccb9af4bf6ac2e Mon Sep 17 00:00:00 2001 From: Bartvds Date: Tue, 21 May 2013 18:16:14 +0200 Subject: [PATCH 2/2] Added definitions for chai's assert-style assertions --- chai/chai-assert-test.ts | 671 +++++++++++++++++++++++++++++++++++++++ chai/chai-assert.d.ts | 113 +++++++ 2 files changed, 784 insertions(+) create mode 100644 chai/chai-assert-test.ts create mode 100644 chai/chai-assert.d.ts diff --git a/chai/chai-assert-test.ts b/chai/chai-assert-test.ts new file mode 100644 index 000000000..b4a5a15be --- /dev/null +++ b/chai/chai-assert-test.ts @@ -0,0 +1,671 @@ +/* + +--------- + test extracted from original test suite + chai original licence follows +--------- + +## License + +(The MIT License) + +Copyright (c) 2011-2013 Jake Luer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/// + +//stubs +declare module chai { + var AssertionError; + function expect(body):any; +} +//tdd +declare function suite(description, action):void; +declare function test(description, action):void; +declare function err(action, msg?):void; +interface FieldObj { + field: any; +} + +suite('assert', function () { + + test('assert', function () { + var foo = 'bar'; + assert(foo == 'bar', "expected foo to equal `bar`"); + + err(function () { + assert(foo == 'baz', "expected foo to equal `bar`"); + }, "expected foo to equal `bar`"); + }); + + test('fail', function () { + chai.expect(function () { + assert.fail(); + }).to.throw(chai.AssertionError); + }); + + test('isTrue', function () { + assert.isTrue(true); + + err(function () { + assert.isTrue(false); + }, "expected false to be true"); + + err(function () { + assert.isTrue(1); + }, "expected 1 to be true"); + + err(function () { + assert.isTrue('test'); + }, "expected 'test' to be true"); + }); + + test('ok', function () { + assert.ok(true); + assert.ok(1); + assert.ok('test'); + + err(function () { + assert.ok(false); + }, "expected false to be truthy"); + + err(function () { + assert.ok(0); + }, "expected 0 to be truthy"); + + err(function () { + assert.ok(''); + }, "expected '' to be truthy"); + }); + + test('isFalse', function () { + assert.isFalse(false); + + err(function () { + assert.isFalse(true); + }, "expected true to be false"); + + err(function () { + assert.isFalse(0); + }, "expected 0 to be false"); + }); + + test('equal', function () { + var foo; + assert.equal(foo, undefined); + }); + + test('typeof / notTypeOf', function () { + assert.typeOf('test', 'string'); + assert.typeOf(true, 'boolean'); + assert.typeOf(5, 'number'); + + err(function () { + assert.typeOf(5, 'string'); + }, "expected 5 to be a string"); + + }); + + test('notTypeOf', function () { + assert.notTypeOf('test', 'number'); + + err(function () { + assert.notTypeOf(5, 'number'); + }, "expected 5 not to be a number"); + }); + + test('instanceOf', function () { + function Foo() { + } + + assert.instanceOf(new Foo(), Foo); + + err(function () { + assert.instanceOf(5, Foo); + }, "expected 5 to be an instance of Foo"); + + function CrashyObject() { + }; + CrashyObject.prototype.inspect = function () { + throw new Error("Arg's inspect() called even though the test passed"); + }; + assert.instanceOf(new CrashyObject(), CrashyObject); + }); + + test('notInstanceOf', function () { + function Foo() { + } + + assert.notInstanceOf(new Foo(), String); + + err(function () { + assert.notInstanceOf(new Foo(), Foo); + }, "expected {} to not be an instance of Foo"); + }); + + test('isObject', function () { + function Foo() { + } + + assert.isObject({}); + assert.isObject(new Foo()); + + err(function () { + assert.isObject(true); + }, "expected true to be an object"); + + err(function () { + assert.isObject(Foo); + }, "expected [Function: Foo] to be an object"); + + err(function () { + assert.isObject('foo'); + }, "expected 'foo' to be an object"); + }); + + test('isNotObject', function () { + function Foo() { + } + + assert.isNotObject(5); + + err(function () { + assert.isNotObject({}); + }, "expected {} not to be an object"); + }); + + test('notEqual', function () { + assert.notEqual(3, 4); + + err(function () { + assert.notEqual(5, 5); + }, "expected 5 to not equal 5"); + }); + + test('strictEqual', function () { + assert.strictEqual('foo', 'foo'); + + err(function () { + assert.strictEqual('5', 5); + }, "expected \'5\' to equal 5"); + }); + + test('notStrictEqual', function () { + assert.notStrictEqual(5, '5'); + + err(function () { + assert.notStrictEqual(5, 5); + }, "expected 5 to not equal 5"); + }); + + test('deepEqual', function () { + assert.deepEqual({tea: 'chai'}, {tea: 'chai'}); + + err(function () { + assert.deepEqual({tea: 'chai'}, {tea: 'black'}); + }, "expected { tea: \'chai\' } to deeply equal { tea: \'black\' }"); + + var obja = Object.create({ tea: 'chai' }) + , objb = Object.create({ tea: 'chai' }); + + assert.deepEqual(obja, objb); + + var obj1 = Object.create({tea: 'chai'}) + , obj2 = Object.create({tea: 'black'}); + + err(function () { + assert.deepEqual(obj1, obj2); + }, "expected { tea: \'chai\' } to deeply equal { tea: \'black\' }"); + }); + + test('deepEqual (ordering)', function () { + var a = { a: 'b', c: 'd' } + , b = { c: 'd', a: 'b' }; + assert.deepEqual(a, b); + }); + + test('deepEqual (circular)', function () { + var circularObject:any = {} + , secondCircularObject:any = {}; + circularObject.field = circularObject; + secondCircularObject.field = secondCircularObject; + + assert.deepEqual(circularObject, secondCircularObject); + + err(function () { + secondCircularObject.field2 = secondCircularObject; + assert.deepEqual(circularObject, secondCircularObject); + }, "expected { field: [Circular] } to deeply equal { Object (field, field2) }"); + }); + + test('notDeepEqual', function () { + assert.notDeepEqual({tea: 'jasmine'}, {tea: 'chai'}); + err(function () { + assert.notDeepEqual({tea: 'chai'}, {tea: 'chai'}); + }, "expected { tea: \'chai\' } to not deeply equal { tea: \'chai\' }"); + }); + + test('notDeepEqual (circular)', function () { + var circularObject:any = {} + , secondCircularObject:any = { tea: 'jasmine' }; + circularObject.field = circularObject; + secondCircularObject.field = secondCircularObject; + + assert.notDeepEqual(circularObject, secondCircularObject); + + err(function () { + delete secondCircularObject.tea; + assert.notDeepEqual(circularObject, secondCircularObject); + }, "expected { field: [Circular] } to not deeply equal { field: [Circular] }"); + }); + + test('isNull', function () { + assert.isNull(null); + + err(function () { + assert.isNull(undefined); + }, "expected undefined to equal null"); + }); + + test('isNotNull', function () { + assert.isNotNull(undefined); + + err(function () { + assert.isNotNull(null); + }, "expected null to not equal null"); + }); + + test('isUndefined', function () { + assert.isUndefined(undefined); + + err(function () { + assert.isUndefined(null); + }, "expected null to equal undefined"); + }); + + test('isDefined', function () { + assert.isDefined(null); + + err(function () { + assert.isDefined(undefined); + }, "expected undefined to not equal undefined"); + }); + + test('isFunction', function () { + var func = function () { + }; + assert.isFunction(func); + + err(function () { + assert.isFunction({}); + }, "expected {} to be a function"); + }); + + test('isNotFunction', function () { + assert.isNotFunction(5); + + err(function () { + assert.isNotFunction(function () { + }); + }, "expected [Function] not to be a function"); + }); + + test('isArray', function () { + assert.isArray([]); + assert.isArray(new Array); + + err(function () { + assert.isArray({}); + }, "expected {} to be an array"); + }); + + test('isNotArray', function () { + assert.isNotArray(3); + + err(function () { + assert.isNotArray([]); + }, "expected [] not to be an array"); + + err(function () { + assert.isNotArray(new Array); + }, "expected [] not to be an array"); + }); + + test('isString', function () { + assert.isString('Foo'); + assert.isString(new String('foo')); + + err(function () { + assert.isString(1); + }, "expected 1 to be a string"); + }); + + test('isNotString', function () { + assert.isNotString(3); + assert.isNotString([ 'hello' ]); + + err(function () { + assert.isNotString('hello'); + }, "expected 'hello' not to be a string"); + }); + + test('isNumber', function () { + assert.isNumber(1); + assert.isNumber(Number('3')); + + err(function () { + assert.isNumber('1'); + }, "expected \'1\' to be a number"); + }); + + test('isNotNumber', function () { + assert.isNotNumber('hello'); + assert.isNotNumber([ 5 ]); + + err(function () { + assert.isNotNumber(4); + }, "expected 4 not to be a number"); + }); + + test('isBoolean', function () { + assert.isBoolean(true); + assert.isBoolean(false); + + err(function () { + assert.isBoolean('1'); + }, "expected \'1\' to be a boolean"); + }); + + test('isNotBoolean', function () { + assert.isNotBoolean('true'); + + err(function () { + assert.isNotBoolean(true); + }, "expected true not to be a boolean"); + + err(function () { + assert.isNotBoolean(false); + }, "expected false not to be a boolean"); + }); + + test('include', function () { + assert.include('foobar', 'bar'); + assert.include([ 1, 2, 3], 3); + + err(function () { + assert.include('foobar', 'baz'); + }, "expected \'foobar\' to contain \'baz\'"); + + err(function () { + assert.include(undefined, 'bar'); + }, "expected an array or string"); + }); + + test('notInclude', function () { + assert.notInclude('foobar', 'baz'); + assert.notInclude([ 1, 2, 3 ], 4); + + err(function () { + assert.notInclude('foobar', 'bar'); + }, "expected \'foobar\' to not contain \'bar\'"); + + err(function () { + assert.notInclude(undefined, 'bar'); + }, "expected an array or string"); + }); + + test('lengthOf', function () { + assert.lengthOf([1, 2, 3], 3); + assert.lengthOf('foobar', 6); + + err(function () { + assert.lengthOf('foobar', 5); + }, "expected 'foobar' to have a length of 5 but got 6"); + + err(function () { + assert.lengthOf(1, 5); + }, "expected 1 to have a property \'length\'"); + }); + + test('match', function () { + assert.match('foobar', /^foo/); + assert.notMatch('foobar', /^bar/); + + err(function () { + assert.match('foobar', /^bar/i); + }, "expected 'foobar' to match /^bar/i"); + + err(function () { + assert.notMatch('foobar', /^foo/i); + }, "expected 'foobar' not to match /^foo/i"); + }); + + test('property', function () { + var obj = { foo: { bar: 'baz' } }; + var simpleObj = { foo: 'bar' }; + 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(function () { + assert.property(obj, 'baz'); + }, "expected { foo: { bar: 'baz' } } to have a property 'baz'"); + + err(function () { + assert.deepProperty(obj, 'foo.baz'); + }, "expected { foo: { bar: 'baz' } } to have a deep property 'foo.baz'"); + + err(function () { + assert.notProperty(obj, 'foo'); + }, "expected { foo: { bar: 'baz' } } to not have property 'foo'"); + + err(function () { + assert.notDeepProperty(obj, 'foo.bar'); + }, "expected { foo: { bar: 'baz' } } to not have deep property 'foo.bar'"); + + err(function () { + assert.propertyVal(simpleObj, 'foo', 'ball'); + }, "expected { foo: 'bar' } to have a property 'foo' of 'ball', but got 'bar'"); + + err(function () { + assert.deepPropertyVal(obj, 'foo.bar', 'ball'); + }, "expected { foo: { bar: 'baz' } } to have a deep property 'foo.bar' of 'ball', but got 'baz'"); + + err(function () { + assert.propertyNotVal(simpleObj, 'foo', 'bar'); + }, "expected { foo: 'bar' } to not have a property 'foo' of 'bar'"); + + err(function () { + assert.deepPropertyNotVal(obj, 'foo.bar', 'baz'); + }, "expected { foo: { bar: 'baz' } } to not have a deep property 'foo.bar' of 'baz'"); + }); + + test('throws', function () { + assert.throws(function () { + throw new Error('foo'); + }); + assert.throws(function () { + throw new Error('bar'); + }, 'bar'); + assert.throws(function () { + throw new Error('bar'); + }, /bar/); + assert.throws(function () { + throw new Error('bar'); + }, Error); + assert.throws(function () { + throw new Error('bar'); + }, Error, 'bar'); + + err(function () { + assert.throws(function () { + throw new Error('foo') + }, TypeError); + }, "expected [Function] to throw 'TypeError' but [Error: foo] was thrown") + + err(function () { + assert.throws(function () { + throw new Error('foo') + }, 'bar'); + }, "expected [Function] to throw error including 'bar' but got 'foo'") + + err(function () { + assert.throws(function () { + throw new Error('foo') + }, Error, 'bar'); + }, "expected [Function] to throw error including 'bar' but got 'foo'") + + err(function () { + assert.throws(function () { + throw new Error('foo') + }, TypeError, 'bar'); + }, "expected [Function] to throw 'TypeError' but [Error: foo] was thrown") + + err(function () { + assert.throws(function () { + }); + }, "expected [Function] to throw an error"); + + err(function () { + assert.throws(function () { + throw new Error('') + }, 'bar'); + }, "expected [Function] to throw error including 'bar' but got ''"); + + err(function () { + assert.throws(function () { + throw new Error('') + }, /bar/); + }, "expected [Function] to throw error matching /bar/ but got ''"); + }); + + test('doesNotThrow', function () { + assert.doesNotThrow(function () { + }); + assert.doesNotThrow(function () { + }, 'foo'); + + err(function () { + assert.doesNotThrow(function () { + throw new Error('foo'); + }); + }, 'expected [Function] to not throw an error but [Error: foo] was thrown'); + }); + + test('ifError', function () { + assert.ifError(false); + assert.ifError(null); + assert.ifError(undefined); + + err(function () { + assert.ifError('foo'); + }, "expected \'foo\' to be falsy"); + }); + + test('operator', function () { + assert.operator(1, '<', 2); + assert.operator(2, '>', 1); + assert.operator(1, '==', 1); + assert.operator(1, '<=', 1); + assert.operator(1, '>=', 1); + assert.operator(1, '!=', 2); + assert.operator(1, '!==', 2); + + err(function () { + assert.operator(1, '=', 2); + }, 'Invalid operator "="'); + + err(function () { + assert.operator(2, '<', 1); + }, "expected 2 to be < 1"); + + err(function () { + assert.operator(1, '>', 2); + }, "expected 1 to be > 2"); + + err(function () { + assert.operator(1, '==', 2); + }, "expected 1 to be == 2"); + + err(function () { + assert.operator(2, '<=', 1); + }, "expected 2 to be <= 1"); + + err(function () { + assert.operator(1, '>=', 2); + }, "expected 1 to be >= 2"); + + err(function () { + assert.operator(1, '!=', 1); + }, "expected 1 to be != 1"); + + err(function () { + assert.operator(1, '!==', '1'); + }, "expected 1 to be !== \'1\'"); + }); + + test('closeTo', function () { + assert.closeTo(1.5, 1.0, 0.5); + assert.closeTo(10, 20, 20); + assert.closeTo(-10, 20, 30); + + err(function () { + assert.closeTo(2, 1.0, 0.5); + }, "expected 2 to be close to 1 +/- 0.5"); + + err(function () { + assert.closeTo(-10, 20, 29); + }, "expected -10 to be close to 20 +/- 29"); + }); + + test('members', function () { + assert.includeMembers([1, 2, 3], [2, 3]); + assert.includeMembers([1, 2, 3], []); + assert.includeMembers([1, 2, 3], [3]); + + err(function () { + assert.includeMembers([5, 6], [7, 8]); + }, 'expected [ 5, 6 ] to be a superset of [ 7, 8 ]'); + + err(function () { + assert.includeMembers([5, 6], [5, 6, 0]); + }, 'expected [ 5, 6 ] to be a superset of [ 5, 6, 0 ]'); + }); + + test('memberEquals', function () { + assert.sameMembers([], []); + assert.sameMembers([1, 2, 3], [3, 2, 1]); + assert.sameMembers([4, 2], [4, 2]); + + err(function () { + assert.sameMembers([], [1, 2]); + }, 'expected [] to have the same members as [ 1, 2 ]'); + + err(function () { + assert.sameMembers([1, 54], [6, 1, 54]); + }, 'expected [ 1, 54 ] to have the same members as [ 6, 1, 54 ]'); + }); + +}); diff --git a/chai/chai-assert.d.ts b/chai/chai-assert.d.ts new file mode 100644 index 000000000..b31b7bde5 --- /dev/null +++ b/chai/chai-assert.d.ts @@ -0,0 +1,113 @@ +// Type definitions for chai v1.6.0 assert style +// Project: http://chaijs.com/ +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module chai +{ + interface Assert + { + (express:any, msg?:string); + + fail(actual?:any, expected?:any, msg?:string, operator?:string); + ok(val:any, msg?:string); + + equal(act:any, exp:any, msg?:string); + notEqual(act:any, exp:any, msg?:string); + + strictEqual(act:any, exp:any, msg?:string); + notStrictEqual(act:any, exp:any, msg?:string); + + deepEqual(act:any, exp:any, msg?:string); + notDeepEqual(act:any, exp:any, msg?:string); + + isTrue(val:any, msg?:string); + isFalse(val:any, msg?:string); + + isNull(val:any, msg?:string); + isNotNull(val:any, msg?:string); + + isUndefined(val:any, msg?:string); + isDefined(val:any, msg?:string); + + isFunction(val:any, msg?:string); + isNotFunction(val:any, msg?:string); + + isObject(val:any, msg?:string); + isNotObject(val:any, msg?:string); + + isArray(val:any, msg?:string); + isNotArray(val:any, msg?:string); + + isString(val:any, msg?:string); + isNotString(val:any, msg?:string); + + isNumber(val:any, msg?:string); + isNotNumber(val:any, msg?:string); + + isBoolean(val:any, msg?:string); + isNotBoolean(val:any, msg?:string); + + typeOf(val:any, type:string, msg?:string); + notTypeOf(val:any, type:string, msg?:string); + + instanceOf(val:any, type:Function, msg?:string); + notInstanceOf(val:any, type:Function, msg?:string); + + include(exp:string, inc:any, msg?:string); + include(exp:any[], inc:any, msg?:string); + + notInclude(exp:string, inc:any, msg?:string); + notInclude(exp:any[], inc:any, msg?:string); + + match(exp:any, re:RegExp, msg?:string); + notMatch(exp:any, re:RegExp, msg?:string); + + property(obj:Object, prop:string, msg?:string); + notProperty(obj:Object, prop:string, msg?:string); + deepProperty(obj:Object, prop:string, msg?:string); + notDeepProperty(obj:Object, prop:string, msg?:string); + + propertyVal(obj:Object, prop:string, val:any, msg?:string); + propertyNotVal(obj:Object, prop:string, val:any, msg?:string); + + + deepPropertyVal(obj:Object, prop:string, val:any, msg?:string); + deepPropertyNotVal(obj:Object, prop:string, val:any, msg?:string); + + lengthOf(exp:any, len:number, msg?:string); + + //alias frenzy + throw(fn:Function, msg?:string); + throw(fn:Function, regExp:RegExp); + throw(fn:Function, errType:Function, msg?:string); + throw(fn:Function, errType:Function, regExp:RegExp); + + throws(fn:Function, msg?:string); + throws(fn:Function, regExp:RegExp); + throws(fn:Function, errType:Function, msg?:string); + throws(fn:Function, errType:Function, regExp:RegExp); + + Throw(fn:Function, msg?:string); + Throw(fn:Function, regExp:RegExp); + Throw(fn:Function, errType:Function, msg?:string); + Throw(fn:Function, errType:Function, regExp:RegExp); + + doesNotThrow(fn:Function, msg?:string); + doesNotThrow(fn:Function, regExp:RegExp); + doesNotThrow(fn:Function, errType:Function, msg?:string); + doesNotThrow(fn:Function, errType:Function, regExp:RegExp); + + operator(val:any, operator:string, val2:any, msg?:string); + closeTo(act:number, exp:number, delta:number, msg?:string); + + sameMembers(set1:any[], set2:any[], msg?:string); + includeMembers(set1:any[], set2:any[], msg?:string); + + ifError(val:any, msg?:string); + } + //node module + declare var assert:Assert; +} +//browser global +declare var assert:chai.Assert; \ No newline at end of file