DEV Community

Discussion on: What is the use of Proxy and Reflect in JavaScript?

Collapse
 
rodrigocnascimento profile image
Rodrigo Nascimento
repositoryClass = module.get<IRepo>(repo);
const queryBuilder = jest.fn().mockReturnValue({
    getMany: jest.fn().mockReturnValue({ ...object }),
});
Reflect.set(
    repositoryClass,
    'queryBuilderMethod',
    queryBuilder
);
Enter fullscreen mode Exit fullscreen mode

I was using typeorm + nestjs + jest so it has a queryBuilder and I wanted that my custom queryBuilderMethod "inherits" some default queryBuilder methods, because in that case, I was using the default plus the custom.
So my other custom methods that depends on those configuration custom + default will have the right params and return the query as intended