feat(test_lib): implement SpyObject
This commit is contained in:
@@ -24,6 +24,7 @@ class Expect extends gns.Expect {
|
||||
void toEqual(expected) => toHaveSameProps(expected);
|
||||
void toThrowError([message=""]) => this.toThrowWith(message: message);
|
||||
void toBePromise() => _expect(actual is Future, equals(true));
|
||||
void toImplement(expected) => toBeA(expected);
|
||||
Function get _expect => gns.guinness.matchers.expect;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,10 +73,51 @@ window.beforeEach(function() {
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toImplement: function() {
|
||||
return {
|
||||
compare: function(actualObject, expectedInterface) {
|
||||
var objProps = Object.keys(actualObject.constructor.prototype);
|
||||
var intProps = Object.keys(expectedInterface.prototype);
|
||||
|
||||
var missedMethods = [];
|
||||
intProps.forEach((k) => {
|
||||
if (!actualObject.constructor.prototype[k]) missedMethods.push(k);
|
||||
});
|
||||
|
||||
return {
|
||||
pass: missedMethods.length == 0,
|
||||
get message() {
|
||||
return 'Expected ' + actualObject + ' to have the following methods: ' + missedMethods.join(", ");
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export class SpyObject {
|
||||
spy(name){
|
||||
if (! this[name]) {
|
||||
this[name] = this._createGuinnessCompatibleSpy();
|
||||
}
|
||||
return this[name];
|
||||
}
|
||||
|
||||
rttsAssert(value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
_createGuinnessCompatibleSpy(){
|
||||
var newSpy = jasmine.createSpy();
|
||||
newSpy.andCallFake = newSpy.and.callFake;
|
||||
return newSpy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mapToString(m) {
|
||||
if (!m) {
|
||||
return ''+m;
|
||||
|
||||
Reference in New Issue
Block a user