@testing-library/angular
Version:
Test your Angular components with the dom-testing-library
51 lines (47 loc) • 1.29 kB
JavaScript
function createMock(type) {
const mock = {};
function mockFunctions(proto) {
if (!proto) {
return;
}
for (const prop of Object.getOwnPropertyNames(proto)) {
if (prop === 'constructor') {
continue;
}
const descriptor = Object.getOwnPropertyDescriptor(proto, prop);
if (typeof descriptor?.value === 'function') {
mock[prop] = jest.fn();
}
}
mockFunctions(Object.getPrototypeOf(proto));
}
mockFunctions(type.prototype);
return mock;
}
function createMockWithValues(type, values) {
const mock = createMock(type);
Object.entries(values).forEach(([field, value]) => {
mock[field] = value;
});
return mock;
}
function provideMock(type) {
return {
provide: type,
useValue: createMock(type),
};
}
function provideMockWithValues(type, values) {
return {
provide: type,
useValue: createMockWithValues(type, values),
};
}
/*
* Public API Surface of testing-library
*/
/**
* Generated bundle index. Do not edit.
*/
export { createMock, createMockWithValues, provideMock, provideMockWithValues };
//# sourceMappingURL=testing-library-angular-jest-utils.mjs.map