Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Feat/mock interface api with generic #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {mock} from './src/index';

export {mock};
export * from './src/index';
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ export function mock(options: Options) {
default:
return mockTS(options);
}
}

export const mockInterface = (optionsWithoutInterfaces: Exclude<Options, "interfaces">) => {
return <TModel>(interfaces: Options["interfaces"]) => {
return mock({...optionsWithoutInterfaces, interfaces}) as unknown as TModel;
}
}
5 changes: 5 additions & 0 deletions src/lang/ts/intermock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,11 @@ function traverseInterfaceMembers(
typeName = node.type.getText();
}

if (typeName === "Date" && kind == ts.SyntaxKind.TypeReference) {
output[property] = generatePrimitive(property, ts.SyntaxKind.StringKeyword, options, "date.past");
return;
}

switch (kind) {
case ts.SyntaxKind.TypeReference:
processPropertyTypeReference(
Expand Down
Loading