Skip to content

Feat/mock interface api with generic #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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