Skip to content

Extension methods for MockBuilder #5417

Closed
@satanTime

Description

Discussed in #5404

Originally posted by AE1NS April 6, 2023
I would love to write some reusable extension methods for the MockBuilder. But as MockBuilder is a function and not a class, I'm struggling a bit how to achieve this.
Thought I could use something like this:
.d.ts:

export {};

declare module 'ng-mocks' {
    interface IMockBuilder {
        mockCustom(): IMockBuilder;
    }
}

.ts:

MockBuilder.prototype.mockCustom = function(): IMockBuilder {
    // some custom stuff on the MockBuilder
    return this;
};

test.spec.ts:

beforeEach(() =>
    MockBuilder(TestComponent)
        .mockCustom()
);

The type is recognized correctly but it will not run, as 'MockBuilder.prototype' cant work on a function. Can you tell me if can extend it on another way externally?

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions