Merge pull request #489 from kazimanzurrashid/master

Updated Backbone and Js-Fixtures
This commit is contained in:
Boris Yankov
2013-05-03 04:04:05 -07:00
12 changed files with 605 additions and 26 deletions
+157 -2
View File
@@ -1,4 +1,5 @@
/// <reference path="backbone.d.ts" />
/// <reference path="../jquery/jquery.d.ts" />
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();
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);
}
}
}
+69 -23
View File
@@ -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,31 +101,34 @@ 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;
isNew(): bool;
isValid(): string;
isValid(): bool;
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;
+68
View File
@@ -0,0 +1,68 @@
/// <reference path="../chai/chai.d.ts" />
/// <reference path="chai-jquery.d.ts" />
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('<div>bar</div>');
}
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');
}
+37
View File
@@ -0,0 +1,37 @@
// Type definitions for chai-jquery 1.1.1
// Project: https://github.com/chaijs/chai-jquery
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../chai/chai.d.ts" />
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;
}
}
+90
View File
@@ -0,0 +1,90 @@
/// <reference path="chai.d.ts" />
var expect = chai.expect;
function test_be() {
expect(true).to.be.ok;
expect(true).to.be.true;
expect(false).to.be.false;
expect(null).to.be.null;
expect(undefined).to.be.undefined;
expect([]).to.be.empty;
expect([]).to.be.arguments;
expect({}).to.be.an('object');
expect({}).to.be.an.instanceof(Object);
expect(5).to.be.at.least(5);
expect(5).to.be.at.gte(5);
expect(5).to.be.at.most(5);
expect(5).to.be.at.lte(5);
expect('').to.be.a('string');
expect(5).to.be.within(1, 6);
expect(5.001).to.be.closeTo(5, 0.5);
}
function test_not() {
expect(5).to.not.be.a('string');
}
function test_deep() {
expect(5).to.deep.equal(5);
expect({ foo: 'bar' }).to.deep.property('foo', 'bar');
}
function test_have() {
expect({ foo: 'bar' }).to.have.property('foo', 'bar');
expect([]).to.have.length(5);
expect({ foo: 'bar' }).to.have.ownProperty('foo');
expect('foo-bar').to.have.string('bar');
expect({ foo: 'bar', baz: 'qux' }).to.have.keys('foo', 'baz');
}
function test_exist() {
var obj = { foo: 'bar' };
expect(obj.foo).to.exist;
}
function test_equal() {
expect(5).to.equal(5);
}
function test_include() {
expect('foo-bar').to.include('o-b');
expect([1,2,3]).to.include(2);
expect({ foo: 'bar', baz: 'qux' }).to.include.keys('foo', 'baz');
expect('foo-bar').to.contain('o-b');
expect([1,2,3]).to.contain(2);
expect({ foo: 'bar', baz: 'qux' }).to.contain.keys('foo', 'baz');
}
function test_throw() {
var foo = {
bar: () => { }
};
expect(foo.bar).to.throw(new Error);
expect(foo.bar).to.throw('An error');
expect(foo.bar).to.throw(/error/);
}
function test_eql() {
var foo = {}
expect(foo).to.eql({});
expect(foo).to.eqls({});
}
function test_match() {
expect('foo-bar').to.match(/foo/);
}
function test_respondTo() {
var foo = {
bar: () => { }
};
expect(foo).to.respondTo('bar');
}
function test_satisfy() {
expect(1).to.satisfy((n) => n > 0);
}
+6 -1
View File
@@ -1,4 +1,9 @@
declare module chai {
// Type definitions for chai 1.5.0
// Project: http://chaijs.com/
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
declare module chai {
interface Equality {
(expected: any, message?: string): bool;
}
+53
View File
@@ -0,0 +1,53 @@
/// <reference path="fixtures.d.ts" />
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('<div></div>');
}
function test_appendSet() {
fixtures.appendSet('<div></div>');
}
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();
}
+5
View File
@@ -1,3 +1,8 @@
// Type definitions for js-fixtures 1.2.0
// Project: https://github.com/badunk/js-fixtures
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
declare interface Fixtures {
path: string;
containerId: string;
+52
View File
@@ -0,0 +1,52 @@
/// <reference path="mocha.d.ts" />
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(); });
}
+5
View File
@@ -1,3 +1,8 @@
// Type definitions for mocha 1.9.0
// Project: http://visionmedia.github.io/mocha/
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
declare var describe : {
(description: string, spec: () => void): void;
only(description: string, spec: () => void): void;
+30
View File
@@ -0,0 +1,30 @@
/// <reference path="../chai/chai.d.ts" />
/// <reference path="sinon-chai.d.ts" />
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');
}
+33
View File
@@ -0,0 +1,33 @@
// Type definitions for sinon-chai 2.4.0
// Project: https://github.com/domenic/sinon-chai
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../chai/chai.d.ts" />
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;
}
}