Skip to content

Commit

Permalink
Changed to createFixture
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Mar 3, 2023
1 parent c1f8bcb commit aa51339
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
13 changes: 9 additions & 4 deletions rEaDMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ it("Should return an id", () => {
});
```

## Pass types to
## API

### `fromExact`

TODO

### `fromAny`

TODO

### `fromPartial`

`fromPartial` lets you pass a deep partial of an object to a slot expecting that
object. This is
TODO

## `createFixture`

## `createMock`
TODO
10 changes: 6 additions & 4 deletions src/createMock.ts → src/createFixture.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Base } from "./types";

const _createMock = <T, Default = {}>(fixture: Default): Base<T, Default> => {
const _createFixture = <T, Default = {}>(
fixture: Default
): Base<T, Default> => {
return {
get: () => fixture as unknown as T,
set: (base) => _createMock(base),
set: (base) => _createFixture(base),
fromExact: (mock) => {
return {
...fixture,
Expand All @@ -25,6 +27,6 @@ const _createMock = <T, Default = {}>(fixture: Default): Base<T, Default> => {
*
* @returns
*/
export const createMock = <T>(): Base<T> => {
return _createMock({});
export const createFixture = <T>(): Base<T> => {
return _createFixture({});
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./types";
export * from "./utils";
export * from "./createMock";
export * from "./createFixture";
4 changes: 2 additions & 2 deletions src/playground.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { it } from "vitest";
import { createMock } from "./createMock";
import { createFixture } from "./createFixture";
import { fromAny, fromPartial, fromExact } from "./utils";

type User = {
Expand All @@ -9,7 +9,7 @@ type User = {

const func = (user: User) => {};

const baseUser = createMock<User>().set({
const baseUser = createFixture<User>().set({
id: "123123",
name: "awdawd",
});
Expand Down
6 changes: 3 additions & 3 deletions tests/createMock.test.ts → tests/createFixture.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from "vitest";
import { createMock } from "../src";
import { createFixture } from "../src";
import { Equal, Expect } from "./test-utils";

describe("createMock", () => {
describe("createFixture", () => {
type User = {
id: number;
name: string;
Expand All @@ -11,7 +11,7 @@ describe("createMock", () => {
}[];
};

const user = createMock<User>();
const user = createFixture<User>();

it("Should start off with an empty object base, but should be assignable to the correct type", () => {
const fixture = user.get();
Expand Down

0 comments on commit aa51339

Please sign in to comment.