Skip to content

Commit

Permalink
feat(testing/utils): create mocks for angular like internals
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Jan 9, 2016
1 parent 7cc33ff commit bb85dc7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/testing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,61 @@ export function getNg1InjectorMock(): ng.auto.IInjectorService {
} as ng.auto.IInjectorService;
}

/**
* @internal
*/
export class $Scope {
$$watchers = [];

$watch( watchExp: Function|string, watchListener: Function ) {
this.$$watchers.push( [ watchExp, watchListener ] );
return function disposable() {}
}

$eval( expression ) {
const toEval = expression;
const done = 'evaluated';
return eval( 'toEval + " " + done' );
}
}

/**
* @internal
*/
export class $Attrs {
$$observers = [];

$observe( attrName, observeListener ) {
this.$$observers.push( [ attrName, observeListener ] );
return function disposable() {}
}
}

/**
*
* @internal
* @constructor
*/
export function ElementFactory() {
return {
_eventListeners:[],
'0': {},
classList: {},
attributes: {},
toggleClass( className, toggle? ){
if ( toggle ) {
this.classList[ className ] = true;
} else {
delete this.classList[ className ];
}
},
attr( attrName, value ){
this.attributes[ attrName ] = value;
},
on(eventName:string,cb:Function){
this._eventListeners.push({ eventName, cb } )
}
}
}


0 comments on commit bb85dc7

Please sign in to comment.