From 2a9a99141879a8145104d9d8052de7fa51391f78 Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Fri, 19 Apr 2013 05:20:09 +0600 Subject: [PATCH 1/9] Updated the signatures and included some of the recent changes of Backbone.js v1.0.0 --- backbone/backbone.d.ts | 90 +++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 6ba1d15a6..183d01bfb 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -12,10 +12,6 @@ declare module Backbone { at: number; } - export interface CreateOptions extends Silenceable { - wait: bool; - } - export interface HistoryOptions extends Silenceable { pushState?: bool; root?: string; @@ -33,27 +29,69 @@ declare module Backbone { silent?: bool; } + interface Validable { + validate?: bool; + } + + interface Waitable { + wait?: bool; + } + + interface Parseable { + parse?: any; + } + + export interface PersistenceOptions { + url?: string; + beforeSend?: (jqxhr: JQueryXHR) => void; + success?: (modelOrCollection?: any, response?: any, options?: any) => void; + error?: (modelOrCollection: any, jqxhr: JQueryXHR, options?: any) => void; + } + + export interface ModelSetOptions extends Silenceable extends Validable { + } + + export interface ModelFetchOptions extends PersistenceOptions extends ModelSetOptions extends Parseable { + } + + export interface ModelSaveOptions extends Silenceable extends Waitable extends Validable extends Parseable extends PersistenceOptions { + patch?: bool; + } + + export interface ModelDestroyOptions extends Waitable extends PersistenceOptions { + } + + export interface CollectionFetchOptions extends PersistenceOptions extends Parseable { + reset?: bool; + } + interface on { (eventName: string, callback: (...args: any[]) => void, context?: any): any; } interface off { (eventName?: string, callback?: (...args: any[]) => void, context?: any): any; } interface trigger { (eventName: string, ...args: any[]): any; } interface bind { (eventName: string, callback: (...args: any[]) => void, context?: any): any; } interface unbind { (eventName?: string, callback?: (...args: any[]) => void, context?: any): any; } - + declare class Events { on(eventName: string, callback: (...args:any[]) => void, context?: any): any; off(eventName?: string, callback?: (...args:any[]) => void, context?: any): any; trigger(eventName: string, ...args: any[]): any; bind(eventName: string, callback: (...args:any[]) => void, context?: any): any; unbind(eventName?: string, callback?: (...args:any[]) => void, context?: any): any; + + once(events: string, callback: (...args: any[]) => void , context?: any): any; + listenTo(object: any, events: string, callback: (...args: any[]) => void ): any; + listenToOnce(object: any, events: string, callback: (...args: any[]) => void ): any; + stopListening(object: any, events?: string, callback?: (...args: any[]) => void ): any; } export class ModelBase extends Events { - fetch(options?: JQueryAjaxSettings); url: any; - parse(response); - toJSON(): any; + parse(response, options?: any); + toJSON(options?: any): any; + sync(...arg: any[]): JQueryXHR; } + export class Model extends ModelBase { static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality @@ -63,21 +101,24 @@ declare module Backbone { cid: string; id: any; idAttribute: string; - urlRoot() : string; + validationError: any; + urlRoot(): string; constructor (attributes?: any, options?: any); initialize(attributes?: any); + fetch(options?: ModelFetchOptions): JQueryXHR; + get(attributeName: string): any; - set(attributeName: string, value: any, options?: Silenceable); - set(obj: any, options?: Silenceable); + set(attributeName: string, value: any, options?: ModelSetOptions); + set(obj: any, options?: ModelSetOptions); change(); changedAttributes(attributes?: any): any[]; clear(options?: Silenceable); clone(): Model; defaults(): any; - destroy(options?: JQueryAjaxSettings); + destroy(options?: ModelDestroyOptions); escape(attribute: string); has(attribute: string): bool; hasChanged(attribute?: string): bool; @@ -85,9 +126,9 @@ declare module Backbone { isValid(): string; previous(attribute: string): any; previousAttributes(): any[]; - save(attributes?: any, options?: JQueryAjaxSettings); + save(attributes?: any, options?: ModelSaveOptions); unset(attribute: string, options?: Silenceable); - validate(attributes: any): any; + validate(attributes: any, options?: any): any; } export class Collection extends ModelBase { @@ -101,6 +142,8 @@ declare module Backbone { constructor (models?: any, options?: any); + fetch(options?: CollectionFetchOptions): JQueryXHR; + comparator(element: Model): number; comparator(element: Model): string; comparator(compare: Model, to?: Model): number; @@ -109,7 +152,7 @@ declare module Backbone { add(models: Model[], options?: AddOptions); at(index: number): Model; get(id: any): Model; - create(attributes: any, options?: CreateOptions): Model; + create(attributes: any, options?: ModelSaveOptions): Model; pluck(attribute: string): any[]; push(model: Model, options?: AddOptions); pop(options?: Silenceable); @@ -124,6 +167,7 @@ declare module Backbone { all(iterator: (element: Model, index: number) => bool, context?: any): bool; any(iterator: (element: Model, index: number) => bool, context?: any): bool; collect(iterator: (element: Model, index: number, context?: any) => any[], context?: any): any[]; + chain(): any; compact(): Model[]; contains(value: any): bool; countBy(iterator: (element: Model, index: number) => any): any[]; @@ -189,6 +233,7 @@ declare module Backbone { initialize (options?: RouterOptions); route(route: string, name: string, callback?: (...parameter: any[]) => void); navigate(fragment: string, options?: NavigateOptions); + navigate(fragment: string, trigger?: bool); } export var history: History; @@ -204,7 +249,7 @@ declare module Backbone { export interface ViewOptions { model?: Backbone.Model; collection?: Backbone.Collection; - el?: Element; + el?: any; id?: string; className?: string; tagName?: string; @@ -217,20 +262,21 @@ declare module Backbone { constructor (options?: ViewOptions); - $(selector: string): any; + $(selector: string): JQuery; model: Model; + collection: Collection; make(tagName: string, attrs?, opts?): View; setElement(element: HTMLElement, delegate?: bool); tagName: string; events: any; - el: HTMLElement; - $el; + el: any; + $el: JQuery; setElement(element); attributes; - $(selector); - render(); - remove(); + $(selector): JQuery; + render(): View; + remove(): View; make(tagName, attributes?, content?); //delegateEvents: any; delegateEvents(events?: any): any; From d977feba3c4dd75fa16ebc81614cd502c6883af6 Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Sat, 20 Apr 2013 08:04:23 +0600 Subject: [PATCH 2/9] Updated file header and included tests. --- js-fixtures/fixtures-tests.ts | 53 +++++++++++++++++++++++++++++++++++ js-fixtures/fixtures.d.ts | 5 ++++ 2 files changed, 58 insertions(+) create mode 100644 js-fixtures/fixtures-tests.ts diff --git a/js-fixtures/fixtures-tests.ts b/js-fixtures/fixtures-tests.ts new file mode 100644 index 000000000..96c15e5d8 --- /dev/null +++ b/js-fixtures/fixtures-tests.ts @@ -0,0 +1,53 @@ +/// + +function test_path() { + fixtures.path = "/fixtures"; +} + +function test_containerId() { + fixtures.containerId = "fixtures"; +} + +function test_body() { + if (!fixtures.body()) { + console.log('body is empty'); + } +} + +function test_window() { + if (!fixtures.window) { + console.log('window is not set'); + } +} + +function test_set() { + fixtures.set('
'); +} + +function test_appendSet() { + fixtures.appendSet('
'); +} + +function test_preload() { + fixtures.preload('/dummy-fixtures.html'); +} + +function test_load() { + fixtures.load('/dummy-fixtures1.html', '/dummy-fixtures2.html'); +} + +function test_appendLoad() { + fixtures.appendLoad('/dummy-fixtures1.html', '/dummy-fixtures2.html'); +} + +function test_read() { + fixtures.read('/dummy-fixtures1.html', '/dummy-fixtures2.html'); +} + +function test_clearCache() { + fixtures.clearCache(); +} + +function test_clearCleanup() { + fixtures.cleanUp(); +} \ No newline at end of file diff --git a/js-fixtures/fixtures.d.ts b/js-fixtures/fixtures.d.ts index dfce88eb7..912bc693c 100644 --- a/js-fixtures/fixtures.d.ts +++ b/js-fixtures/fixtures.d.ts @@ -1,3 +1,8 @@ +// Type definitions for js-fixtures 1.2.0 +// Project: https://github.com/badunk/js-fixtures +// Definitions by: Kazi Manzur Rashid +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + declare interface Fixtures { path: string; containerId: string; From 0fea2d1a864aca85e32ff7f2117ad64558ffa2ee Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Sat, 20 Apr 2013 09:59:51 +0600 Subject: [PATCH 3/9] Added the test for the previous changes. --- backbone/backbone-tests.ts | 159 ++++++++++++++++++++++++++++++++++++- backbone/backbone.d.ts | 2 +- 2 files changed, 158 insertions(+), 3 deletions(-) diff --git a/backbone/backbone-tests.ts b/backbone/backbone-tests.ts index f89b73196..2a2bf3b41 100644 --- a/backbone/backbone-tests.ts +++ b/backbone/backbone-tests.ts @@ -1,4 +1,5 @@ /// +/// declare var _, $; @@ -82,7 +83,6 @@ class Employee extends Backbone.Model { } class EmployeeCollection extends Backbone.Collection { - url: string = "../api/employees"; findByName(key) { } } function test_collection() { @@ -111,4 +111,159 @@ function test_collection() { ////////// -Backbone.history.start(); \ No newline at end of file +Backbone.history.start(); + +module v1Changes { + module events { + function test_once() { + var model = new Employee; + model.once('invalid', () => { }, this); + model.once('invalid', () => { }); + } + + function test_listenTo() { + var model = new Employee; + var view = new Backbone.View; + view.listenTo(model, 'invalid', () => { }); + } + + function test_listenToOnce() { + var model = new Employee; + var view = new Backbone.View; + view.listenToOnce(model, 'invalid', () => { }); + } + + function test_stopListening() { + var model = new Employee; + var view = new Backbone.View; + view.stopListening(model, 'invalid', () => { }); + view.stopListening(model, 'invalid'); + view.stopListening(model); + } + } + + module modelandcollection { + function test_url() { + Employee.prototype.url = () => '/employees'; + EmployeeCollection.prototype.url = () => '/employees'; + } + + function test_parse() { + var model = new Employee(); + model.parse('{}', {}); + var collection = new EmployeeCollection; + collection.parse('{}', {}); + } + + function test_toJSON() { + var model = new Employee(); + model.toJSON({}); + var collection = new EmployeeCollection; + collection.toJSON({}); + } + + function test_sync() { + var model = new Employee(); + model.sync(); + var collection = new EmployeeCollection; + collection.sync(); + } + } + + module model { + function test_validationError() { + var model = new Employee; + if (model.validationError) { + console.log('has validation errors'); + } + } + + function test_fetch() { + var model = new Employee({ id: 1 }); + model.fetch({ + success: () => { }, + error: () => { } + }); + } + + function test_set() { + var model = new Employee; + model.set({ name: 'JoeDoe', age: 21 }, { validate: false }); + model.set('name', 'JoeDoes', { validate: false }); + } + + function test_destroy() { + var model = new Employee; + model.destroy({ + wait: true, + success: (m?, response?, options?) => { }, + error: (m?, jqxhr?: JQueryXHR, options?) => { } + }); + + model.destroy({ + success: (m?, response?, options?) => { }, + error: (m?, jqxhr?: JQueryXHR) => { } + }); + + model.destroy({ + success: () => { }, + error: (m?, jqxhr?: JQueryXHR) => { } + }); + } + + function test_save() { + var model = new Employee; + + model.save({ + name: 'Joe Doe', + age: 21 + }, + { + wait: true, + validate: false, + success: (m?, response?, options?) => { }, + error: (m?, jqxhr?: JQueryXHR, options?) => { } + }); + + model.save({ + name: 'Joe Doe', + age: 21 + }, + { + success: () => { }, + error: (m?, jqxhr?: JQueryXHR) => { } + }); + } + + function test_validate() { + var model = new Employee; + + model.validate({ name: 'JoeDoe', age: 21 }, { validateAge: false }) + } + } + + module collection { + function test_fetch() { + var collection = new EmployeeCollection; + collection.fetch({ reset: true }); + } + + function test_create() { + var collection = new EmployeeCollection; + var model = new Employee; + + collection.create(model, { + validate: false + }); + } + } + + module router { + function test_navigate() { + var router = new Backbone.Router; + + router.navigate('/employees', { trigger: true }); + router.navigate('/employees', true); + } + } +} \ No newline at end of file diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 183d01bfb..1ff7374a4 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -45,7 +45,7 @@ declare module Backbone { url?: string; beforeSend?: (jqxhr: JQueryXHR) => void; success?: (modelOrCollection?: any, response?: any, options?: any) => void; - error?: (modelOrCollection: any, jqxhr: JQueryXHR, options?: any) => void; + error?: (modelOrCollection?: any, jqxhr?: JQueryXHR, options?: any) => void; } export interface ModelSetOptions extends Silenceable extends Validable { From fa81134a206f161a649d1d1b4c28c91cbfc35fa4 Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Sat, 20 Apr 2013 10:18:58 +0600 Subject: [PATCH 4/9] Updated file header and included tests. --- mocha/mocha-tests.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++ mocha/mocha.d.ts | 5 +++++ 2 files changed, 57 insertions(+) create mode 100644 mocha/mocha-tests.ts diff --git a/mocha/mocha-tests.ts b/mocha/mocha-tests.ts new file mode 100644 index 000000000..53c8e5720 --- /dev/null +++ b/mocha/mocha-tests.ts @@ -0,0 +1,52 @@ +/// + +function test_describe() { + describe('something', () => { }); + + describe.only('something', () => { }); + + describe.skip('something', () => { }); + + describe('something', function() { + this.timeout(2000); + }); +} + +function test_it() { + + it('does something', () => { }); + + it('does something', (done) => { done(); }); + + it.only('does something', () => { }); + + it.skip('does something', () => { }); + + it('does something', function () { + this.timeout(2000); + }); +} + +function test_before() { + before(() => { }); + + before((done) => { done(); }); +} + +function test_after() { + after(() => { }); + + after((done) => { done(); }); +} + +function test_beforeEach() { + beforeEach(() => { }); + + beforeEach((done) => { done(); }); +} + +function test_afterEach() { + afterEach(() => { }); + + afterEach((done) => { done(); }); +} \ No newline at end of file diff --git a/mocha/mocha.d.ts b/mocha/mocha.d.ts index b722277c3..93b894ed6 100644 --- a/mocha/mocha.d.ts +++ b/mocha/mocha.d.ts @@ -1,3 +1,8 @@ +// Type definitions for mocha 1.9.0 +// Project: http://visionmedia.github.io/mocha/ +// Definitions by: Kazi Manzur Rashid +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + declare var describe : { (description: string, spec: () => void): void; only(description: string, spec: () => void): void; From 8b4a4986446a39bb4d1414f4650943d424757920 Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Mon, 29 Apr 2013 23:00:56 +0600 Subject: [PATCH 5/9] Added sinon-chai definition file. --- sinon-chai/sinon-chai.expect.d.ts | 33 +++++++++++++++++++++++++++++++ sinon-chai/sinon-chai.expect.ts | 30 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 sinon-chai/sinon-chai.expect.d.ts create mode 100644 sinon-chai/sinon-chai.expect.ts diff --git a/sinon-chai/sinon-chai.expect.d.ts b/sinon-chai/sinon-chai.expect.d.ts new file mode 100644 index 000000000..da5c88338 --- /dev/null +++ b/sinon-chai/sinon-chai.expect.d.ts @@ -0,0 +1,33 @@ +// Type definitions for sinon-chai expect 2.4.0 +// Project: https://github.com/domenic/sinon-chai +// Definitions by: Kazi Manzur Rashid +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +///  + +declare module chai { + interface Been { + called: bool; + calledOnce: bool; + calledTwice: bool; + calledThrice: bool; + calledBefore(spy: any): bool; + calledAfter(spy: any): bool; + calledOn(context: any): bool; + alwaysCalledOn(context: any): bool; + calledWith(...args: any[]): bool; + alwaysCalledWith(...args: any[]): bool; + calledWithExactly(...args: any[]): bool; + alwaysCalledWithExactly(...args: any[]): bool; + calledWithMatch(...args: any[]): bool; + alwaysCalledWithMatch(...args: any[]): bool; + returned(returnVal: any): bool; + alwaysReturned(returnVal: any): bool; + threw(errorObjOrErrorTypeStringOrNothing: any): bool; + alwaysThrew(errorObjOrErrorTypeStringOrNothing: any): bool; + } + + interface Have { + been: Been; + } +} \ No newline at end of file diff --git a/sinon-chai/sinon-chai.expect.ts b/sinon-chai/sinon-chai.expect.ts new file mode 100644 index 000000000..ef4b4b784 --- /dev/null +++ b/sinon-chai/sinon-chai.expect.ts @@ -0,0 +1,30 @@ +///  +///  + +var expect = chai.expect; + +function test() { + var spy; + var anotherSpy; + var context; + var match; + + expect(spy).to.have.been.called; + expect(spy).to.have.been.calledOnce; + expect(spy).to.have.been.calledTwice; + expect(spy).to.have.been.calledThrice; + expect(spy).to.have.been.calledBefore(anotherSpy); + expect(spy).to.have.been.calledAfter(anotherSpy); + expect(spy).to.have.been.calledOn(context); + expect(spy).to.have.been.alwaysCalledOn(context); + expect(spy).to.have.been.calledWith('foo', 'bar'); + expect(spy).to.have.been.alwaysCalledWith('foo', 'bar'); + expect(spy).to.have.been.calledWithExactly('foo', 'bar'); + expect(spy).to.have.been.alwaysCalledWithExactly('foo', 'bar'); + expect(spy).to.have.been.calledWithMatch(match); + expect(spy).to.have.been.alwaysCalledWithMatch(match); + expect(spy).to.have.been.returned(1); + expect(spy).to.have.been.alwaysReturned(1); + expect(spy).to.have.been.threw('an error'); + expect(spy).to.have.been.alwaysThrew('an error'); +} \ No newline at end of file From fe8140afe8e32d3cdeebc7601d0a7139a17df0c6 Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Mon, 29 Apr 2013 23:56:35 +0600 Subject: [PATCH 6/9] Renamed files. --- sinon-chai/{sinon-chai.expect.ts => sinon-chai-test.ts} | 0 sinon-chai/{sinon-chai.expect.d.ts => sinon-chai.d.ts} | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename sinon-chai/{sinon-chai.expect.ts => sinon-chai-test.ts} (100%) rename sinon-chai/{sinon-chai.expect.d.ts => sinon-chai.d.ts} (95%) diff --git a/sinon-chai/sinon-chai.expect.ts b/sinon-chai/sinon-chai-test.ts similarity index 100% rename from sinon-chai/sinon-chai.expect.ts rename to sinon-chai/sinon-chai-test.ts diff --git a/sinon-chai/sinon-chai.expect.d.ts b/sinon-chai/sinon-chai.d.ts similarity index 95% rename from sinon-chai/sinon-chai.expect.d.ts rename to sinon-chai/sinon-chai.d.ts index da5c88338..00a9dc6f7 100644 --- a/sinon-chai/sinon-chai.expect.d.ts +++ b/sinon-chai/sinon-chai.d.ts @@ -1,4 +1,4 @@ -// Type definitions for sinon-chai expect 2.4.0 +// Type definitions for sinon-chai 2.4.0 // Project: https://github.com/domenic/sinon-chai // Definitions by: Kazi Manzur Rashid // DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped @@ -30,4 +30,4 @@ declare module chai { interface Have { been: Been; } -} \ No newline at end of file +} From 5362cb55c3347438acd1df5ba3050c27f56ef59d Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Tue, 30 Apr 2013 12:56:41 +0600 Subject: [PATCH 7/9] Included Test for Chai and renamed files to follow the project convention. --- chai/chai-tests.ts | 90 +++++++++++++++++++ chai/{chai.expect.d.ts => chai.d.ts} | 7 +- ...sinon-chai-test.ts => sinon-chai-tests.ts} | 4 +- sinon-chai/sinon-chai.d.ts | 2 +- 4 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 chai/chai-tests.ts rename chai/{chai.expect.d.ts => chai.d.ts} (92%) rename sinon-chai/{sinon-chai-test.ts => sinon-chai-tests.ts} (91%) diff --git a/chai/chai-tests.ts b/chai/chai-tests.ts new file mode 100644 index 000000000..ab26aadbc --- /dev/null +++ b/chai/chai-tests.ts @@ -0,0 +1,90 @@ +/// + +var expect = chai.expect; + +function test_be() { + expect(true).to.be.ok; + expect(true).to.be.true; + expect(false).to.be.false; + expect(null).to.be.null; + expect(undefined).to.be.undefined; + expect([]).to.be.empty; + expect([]).to.be.arguments; + expect({}).to.be.an('object'); + expect({}).to.be.an.instanceof(Object); + expect(5).to.be.at.least(5); + expect(5).to.be.at.gte(5); + expect(5).to.be.at.most(5); + expect(5).to.be.at.lte(5); + expect('').to.be.a('string'); + expect(5).to.be.within(1, 6); + expect(5.001).to.be.closeTo(5, 0.5); +} + +function test_not() { + expect(5).to.not.be.a('string'); +} + +function test_deep() { + expect(5).to.deep.equal(5); + expect({ foo: 'bar' }).to.deep.property('foo', 'bar'); +} + +function test_have() { + expect({ foo: 'bar' }).to.have.property('foo', 'bar'); + expect([]).to.have.length(5); + expect({ foo: 'bar' }).to.have.ownProperty('foo'); + expect('foo-bar').to.have.string('bar'); + expect({ foo: 'bar', baz: 'qux' }).to.have.keys('foo', 'baz'); +} + +function test_exist() { + var obj = { foo: 'bar' }; + expect(obj.foo).to.exist; +} + +function test_equal() { + expect(5).to.equal(5); +} + +function test_include() { + expect('foo-bar').to.include('o-b'); + expect([1,2,3]).to.include(2); + expect({ foo: 'bar', baz: 'qux' }).to.include.keys('foo', 'baz'); + + expect('foo-bar').to.contain('o-b'); + expect([1,2,3]).to.contain(2); + expect({ foo: 'bar', baz: 'qux' }).to.contain.keys('foo', 'baz'); +} + +function test_throw() { + var foo = { + bar: () => { } + }; + + expect(foo.bar).to.throw(new Error); + expect(foo.bar).to.throw('An error'); + expect(foo.bar).to.throw(/error/); +} + +function test_eql() { + var foo = {} + expect(foo).to.eql({}); + expect(foo).to.eqls({}); +} + +function test_match() { + expect('foo-bar').to.match(/foo/); +} + +function test_respondTo() { + var foo = { + bar: () => { } + }; + + expect(foo).to.respondTo('bar'); +} + +function test_satisfy() { + expect(1).to.satisfy((n) => n > 0); +} \ No newline at end of file diff --git a/chai/chai.expect.d.ts b/chai/chai.d.ts similarity index 92% rename from chai/chai.expect.d.ts rename to chai/chai.d.ts index eccb443c4..df9e12382 100644 --- a/chai/chai.expect.d.ts +++ b/chai/chai.d.ts @@ -1,4 +1,9 @@ -declare module chai { +// Type definitions for chai 1.5.0 +// Project: http://chaijs.com/ +// Definitions by: Kazi Manzur Rashid +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +declare module chai { interface Equality { (expected: any, message?: string): bool; } diff --git a/sinon-chai/sinon-chai-test.ts b/sinon-chai/sinon-chai-tests.ts similarity index 91% rename from sinon-chai/sinon-chai-test.ts rename to sinon-chai/sinon-chai-tests.ts index ef4b4b784..1ada034de 100644 --- a/sinon-chai/sinon-chai-test.ts +++ b/sinon-chai/sinon-chai-tests.ts @@ -1,5 +1,5 @@ -///  -///  +///  +///  var expect = chai.expect; diff --git a/sinon-chai/sinon-chai.d.ts b/sinon-chai/sinon-chai.d.ts index 00a9dc6f7..93e264ac2 100644 --- a/sinon-chai/sinon-chai.d.ts +++ b/sinon-chai/sinon-chai.d.ts @@ -3,7 +3,7 @@ // Definitions by: Kazi Manzur Rashid // DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped -///  +/// declare module chai { interface Been { From 44e02ee490999a4accd9cfddaf492acc034f84fa Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Tue, 30 Apr 2013 13:47:47 +0600 Subject: [PATCH 8/9] Included chai-jquery definition --- chai-jquery/chai-jquery-tests.ts | 68 ++++++++++++++++++++++++++++++++ chai-jquery/chai-jquery.d.ts | 37 +++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 chai-jquery/chai-jquery-tests.ts create mode 100644 chai-jquery/chai-jquery.d.ts diff --git a/chai-jquery/chai-jquery-tests.ts b/chai-jquery/chai-jquery-tests.ts new file mode 100644 index 000000000..fbd05480e --- /dev/null +++ b/chai-jquery/chai-jquery-tests.ts @@ -0,0 +1,68 @@ +///  +///  + +declare var $; +var expect = chai.expect; + +function test_attr() { + expect($('#foo')).to.have.attr('id'); + expect($('#foo')).to.have.attr('class', 'container'); +} + +function test_css() { + expect($('#foo')).to.have.css('color'); + expect($('#foo')).to.have.css('font-family', 'serif'); +} + +function test_data() { + expect($('#foo')).to.have.data('toggle'); + expect($('#foo')).to.have.css('toggle', 'true'); +} + +function test_class() { + expect($('#foo')).to.have.class('container'); +} + +function test_id() { + expect($('#foo')).to.have.id('foo'); +} + +function test_html() { + expect($('#foo')).to.have.html('
bar
'); +} + +function test_text() { + expect($('#foo')).to.have.text('bar'); +} + +function test_value() { + expect($('#foo')).to.have.value('bar'); +} + +function test_visible() { + expect($('#foo')).to.be.visible; +} + +function test_hidden() { + expect($('#foo')).to.be.hidden; +} + +function test_selected() { + expect($('#foo')).to.be.selected; +} + +function test_checked() { + expect($('#foo')).to.be.checked; +} + +function test_disabled() { + expect($('#foo')).to.be.disabled; +} + +function test_be_selector() { + expect($('#foo')).to.be(':empty'); +} + +function test_have_selector() { + expect($('#foo')).to.have('div'); +} \ No newline at end of file diff --git a/chai-jquery/chai-jquery.d.ts b/chai-jquery/chai-jquery.d.ts new file mode 100644 index 000000000..d038c76ff --- /dev/null +++ b/chai-jquery/chai-jquery.d.ts @@ -0,0 +1,37 @@ +// Type definitions for chai-jquery 1.1.1 +// Project: https://github.com/chaijs/chai-jquery +// Definitions by: Kazi Manzur Rashid +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module chai { + interface NameValueRegexMatcher { + match(value: RegExp): bool; + } + + interface NameValueMatcher { + (name: string, value?: string): bool; + } + + interface Have { + attr: NameValueMatcher; + css: NameValueMatcher; + data: NameValueMatcher; + class(className: string): bool; + id(id: string): bool; + html(html: string): bool; + text(text: string): bool; + value(text: string): bool; + (selector: string): bool; + } + + interface Be { + visible: bool; + hidden: bool; + selected: bool; + checked: bool; + disabled: bool; + (selector: string): bool; + } +} From d2e0be3ea9608bf8e70f1d1f87e2dc9dafca6d7c Mon Sep 17 00:00:00 2001 From: Kazi Manzur Rashid Date: Tue, 30 Apr 2013 13:54:50 +0600 Subject: [PATCH 9/9] Model isValid should return boolean instead of string --- backbone/backbone.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 1ff7374a4..921b84e2f 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -123,7 +123,7 @@ declare module Backbone { has(attribute: string): bool; hasChanged(attribute?: string): bool; isNew(): bool; - isValid(): string; + isValid(): bool; previous(attribute: string): any; previousAttributes(): any[]; save(attributes?: any, options?: ModelSaveOptions);