@ -29,27 +29,33 @@ describe('utils', function() {
|
||||
expect(name).toEqual('method');
|
||||
delegateMethod = delegate;
|
||||
delegateSymbol = symbol;
|
||||
return function(self, args) { return delegate.apply(self, ['patch', args[0]]); };
|
||||
})).toBe(delegateMethod !);
|
||||
return function(self, args) {
|
||||
return delegate.apply(self, ['patch', args[0]]);
|
||||
};
|
||||
})).toBe(delegateMethod!);
|
||||
|
||||
expect(instance.method('a0')).toEqual('OK');
|
||||
expect(args).toEqual(['patch', 'a0']);
|
||||
expect(self).toBe(instance);
|
||||
expect(delegateMethod !).toBe(method);
|
||||
expect(delegateSymbol !).toEqual(zoneSymbol('method'));
|
||||
expect((Type.prototype as any)[delegateSymbol !]).toBe(method);
|
||||
expect(delegateMethod!).toBe(method);
|
||||
expect(delegateSymbol!).toEqual(zoneSymbol('method'));
|
||||
expect((Type.prototype as any)[delegateSymbol!]).toBe(method);
|
||||
});
|
||||
|
||||
it('should not double patch', () => {
|
||||
const Type = function() {};
|
||||
const method = Type.prototype.method = function() {};
|
||||
patchMethod(Type.prototype, 'method', (delegate) => {
|
||||
return function(self, args: any[]) { return delegate.apply(self, ['patch', ...args]); };
|
||||
return function(self, args: any[]) {
|
||||
return delegate.apply(self, ['patch', ...args]);
|
||||
};
|
||||
});
|
||||
const pMethod = Type.prototype.method;
|
||||
expect(pMethod).not.toBe(method);
|
||||
patchMethod(Type.prototype, 'method', (delegate) => {
|
||||
return function(self, args) { return delegate.apply(self, ['patch', ...args]); };
|
||||
return function(self, args) {
|
||||
return delegate.apply(self, ['patch', ...args]);
|
||||
};
|
||||
});
|
||||
expect(pMethod).toBe(Type.prototype.method);
|
||||
});
|
||||
@ -68,8 +74,8 @@ describe('utils', function() {
|
||||
}
|
||||
patchProperty(TestType.prototype, 'nonConfigurableProperty');
|
||||
const desc = Object.getOwnPropertyDescriptor(TestType.prototype, 'nonConfigurableProperty');
|
||||
expect(desc !.writable).toBeTruthy();
|
||||
expect(!desc !.get).toBeTruthy();
|
||||
expect(desc!.writable).toBeTruthy();
|
||||
expect(!desc!.get).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -80,13 +86,17 @@ describe('utils', function() {
|
||||
const log: string[] = [];
|
||||
Object.defineProperties(TestFunction.prototype, {
|
||||
'property1': {
|
||||
value: function Property1(callback: Function) { Zone.root.run(callback); },
|
||||
value: function Property1(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
},
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
},
|
||||
'property2': {
|
||||
value: function Property2(callback: Function) { Zone.root.run(callback); },
|
||||
value: function Property2(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
},
|
||||
writable: true,
|
||||
configurable: false,
|
||||
enumerable: true
|
||||
@ -97,8 +107,12 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property1(() => { log.push('property1' + Zone.current.name); });
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property1(() => {
|
||||
log.push('property1' + Zone.current.name);
|
||||
});
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property1<root>', 'property2<root>']);
|
||||
log.length = 0;
|
||||
@ -107,8 +121,12 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property1(() => { log.push('property1' + Zone.current.name); });
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property1(() => {
|
||||
log.push('property1' + Zone.current.name);
|
||||
});
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property1patch', 'property2patch']);
|
||||
});
|
||||
@ -119,13 +137,17 @@ describe('utils', function() {
|
||||
const log: string[] = [];
|
||||
Object.defineProperties(TestFunction.prototype, {
|
||||
'property1': {
|
||||
value: function Property1(callback: Function) { Zone.root.run(callback); },
|
||||
value: function Property1(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
},
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
},
|
||||
'property2': {
|
||||
value: function Property2(callback: Function) { Zone.root.run(callback); },
|
||||
value: function Property2(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
},
|
||||
writable: false,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
@ -136,8 +158,12 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property1(() => { log.push('property1' + Zone.current.name); });
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property1(() => {
|
||||
log.push('property1' + Zone.current.name);
|
||||
});
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property1<root>', 'property2<root>']);
|
||||
log.length = 0;
|
||||
@ -146,8 +172,12 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property1(() => { log.push('property1' + Zone.current.name); });
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property1(() => {
|
||||
log.push('property1' + Zone.current.name);
|
||||
});
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property1patch', 'property2<root>']);
|
||||
});
|
||||
@ -160,17 +190,23 @@ describe('utils', function() {
|
||||
'property1': {
|
||||
get: function() {
|
||||
if (!this._property1) {
|
||||
this._property1 = function Property2(callback: Function) { Zone.root.run(callback); };
|
||||
this._property1 = function Property2(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
};
|
||||
}
|
||||
return this._property1;
|
||||
},
|
||||
set: function(func: Function) { this._property1 = func; },
|
||||
set: function(func: Function) {
|
||||
this._property1 = func;
|
||||
},
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
},
|
||||
'property2': {
|
||||
get: function() {
|
||||
return function Property2(callback: Function) { Zone.root.run(callback); };
|
||||
return function Property2(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
};
|
||||
},
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
@ -181,8 +217,12 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property1(() => { log.push('property1' + Zone.current.name); });
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property1(() => {
|
||||
log.push('property1' + Zone.current.name);
|
||||
});
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property1<root>', 'property2<root>']);
|
||||
log.length = 0;
|
||||
@ -191,8 +231,12 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property1(() => { log.push('property1' + Zone.current.name); });
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property1(() => {
|
||||
log.push('property1' + Zone.current.name);
|
||||
});
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property1patch', 'property2<root>']);
|
||||
});
|
||||
@ -203,7 +247,9 @@ describe('utils', function() {
|
||||
const log: string[] = [];
|
||||
Object.defineProperties(TestFunction.prototype, {
|
||||
'property2': {
|
||||
value: function Property2(callback: Function) { Zone.root.run(callback); },
|
||||
value: function Property2(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
},
|
||||
writable: false,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
@ -214,7 +260,9 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property2<root>']);
|
||||
log.length = 0;
|
||||
@ -222,12 +270,16 @@ describe('utils', function() {
|
||||
patchMethod(
|
||||
TestFunction.prototype, 'property2',
|
||||
function(delegate: Function, delegateName: string, name: string) {
|
||||
return function(self: any, args: any) { log.push('patched property2'); };
|
||||
return function(self: any, args: any) {
|
||||
log.push('patched property2');
|
||||
};
|
||||
});
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property2<root>']);
|
||||
});
|
||||
@ -239,7 +291,9 @@ describe('utils', function() {
|
||||
Object.defineProperties(TestFunction.prototype, {
|
||||
'property2': {
|
||||
get: function() {
|
||||
return function Property2(callback: Function) { Zone.root.run(callback); };
|
||||
return function Property2(callback: Function) {
|
||||
Zone.root.run(callback);
|
||||
};
|
||||
},
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
@ -250,7 +304,9 @@ describe('utils', function() {
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property2<root>']);
|
||||
log.length = 0;
|
||||
@ -258,12 +314,16 @@ describe('utils', function() {
|
||||
patchMethod(
|
||||
TestFunction.prototype, 'property2',
|
||||
function(delegate: Function, delegateName: string, name: string) {
|
||||
return function(self: any, args: any) { log.push('patched property2'); };
|
||||
return function(self: any, args: any) {
|
||||
log.push('patched property2');
|
||||
};
|
||||
});
|
||||
|
||||
zone.run(() => {
|
||||
const instance = new TestFunction();
|
||||
instance.property2(() => { log.push('property2' + Zone.current.name); });
|
||||
instance.property2(() => {
|
||||
log.push('property2' + Zone.current.name);
|
||||
});
|
||||
});
|
||||
expect(log).toEqual(['property2<root>']);
|
||||
});
|
||||
|
Reference in New Issue
Block a user