fix createExpect to retain asymmetric matchers
This commit is contained in:
parent
eaedd43a2f
commit
978cd7d80a
|
|
@ -153,6 +153,7 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re
|
||||||
return (matcher as any).call(newThis, ...args);
|
return (matcher as any).call(newThis, ...args);
|
||||||
};
|
};
|
||||||
Object.defineProperty(wrappedMatchers[key], 'name', { value: name });
|
Object.defineProperty(wrappedMatchers[key], 'name', { value: name });
|
||||||
|
Object.defineProperty(wrappedMatchers[key], 'qualifiedName', { value: key });
|
||||||
extendedMatchers[name] = wrappedMatchers[key];
|
extendedMatchers[name] = wrappedMatchers[key];
|
||||||
}
|
}
|
||||||
expectLibrary.extend(wrappedMatchers);
|
expectLibrary.extend(wrappedMatchers);
|
||||||
|
|
@ -176,6 +177,24 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re
|
||||||
return configure({ _poll: poll })(actual, messageOrOptions) as any;
|
return configure({ _poll: poll })(actual, messageOrOptions) as any;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof property === 'string' && typeof customMatchers[property] === 'function' && typeof (customMatchers[property] as any).qualifiedName === 'string') {
|
||||||
|
const qualifiedName = (customMatchers[property] as any).qualifiedName as string;
|
||||||
|
return (expectLibrary as any)[qualifiedName];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'not') {
|
||||||
|
return new Proxy(expectLibrary, {
|
||||||
|
get: function(target: any, property: string) {
|
||||||
|
if (typeof property === 'string' && typeof customMatchers[property] === 'function' && typeof (customMatchers[property] as any).qualifiedName === 'string') {
|
||||||
|
const qualifiedName = (customMatchers[property] as any).qualifiedName as string;
|
||||||
|
return (expectLibrary as any)['not'][qualifiedName];
|
||||||
|
}
|
||||||
|
return (expectLibrary as any)['not'][property];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (expectLibrary as any)[property];
|
return (expectLibrary as any)[property];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue