1
>
/*---------------------------------------------------------------------------------------------
mock.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { SinonStub, stub } from 'sinon';
7
>
import { DeepPartial } from '../../common/types.js';
8
>
9
>
export interface Ctor<T> {
10
>
new(): T;
11
>
}
12
>
13
>
export function mock<T>(): Ctor<T> {
14
// eslint-disable-next-line local/code-no-any-casts
15
return function () { } as any;
16
}
18
>
export type MockObject<T, ExceptProps = never> = { [K in keyof T]: K extends ExceptProps ? T[K] : SinonStub };
19
>
20
>
// Creates an object object that returns sinon mocks for every property. Optionally
21
>
// takes base properties.
22
>
export const mockObject = <T extends object>() => <TP extends Partial<T> = {}>(properties?: TP): MockObject<T, keyof TP> => {
23
// eslint-disable-next-line local/code-no-any-casts
24
return new Proxy({ ...properties } as any, {