Skip to content
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

test @arktype/attest #11446

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ esbuild-why-*.html

.yalc
yalc.lock

.attest
5 changes: 5 additions & 0 deletions config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ const defaults = {
},
},
],
"\\.js$": [
"babel-jest",
{ configFile: "./src/config/jest/babel.config.js" },
],
},
transformIgnorePatterns: ["node_modules/(?!(@arktype))"],
resolver: "ts-jest-resolver",
};

Expand Down
1 change: 1 addition & 0 deletions eslint-local-rules/fixtures/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions eslint-local-rules/fixtures/react.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
141 changes: 101 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "0.13.3",
"@arktype/attest": "^0.5.0",
"@babel/parser": "7.23.5",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@graphql-tools/schema": "10.0.2",
Expand Down
7 changes: 7 additions & 0 deletions src/config/jest/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (api) {
api.cache(true);
return {
presets: [],
plugins: ["@babel/plugin-transform-modules-commonjs"],
};
};
45 changes: 34 additions & 11 deletions src/react/hooks/__tests__/useLoadableQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ import {
spyOnConsole,
useTrackRenders,
} from "../../../testing/internal";
import { attest, setup, cleanup } from "@arktype/attest";

beforeAll(setup);
afterAll(cleanup);

afterEach(() => {
jest.useRealTimers();
Expand Down Expand Up @@ -4645,7 +4649,14 @@ it("allows loadQuery to be called in useEffect on first render", async () => {
expect(() => renderWithMocks(<App />, { mocks })).not.toThrow();
});

describe.skip("type tests", () => {
type UseLoadableQuery = typeof useLoadableQuery;
type Gql = typeof gql;
type UseReadQuery = typeof useReadQuery;
describe("type tests", () => {
const useLoadableQuery = (() => [() => {}, {}]) as any as UseLoadableQuery;
const gql = (() => {}) as any as Gql;
const useReadQuery = (() => ({})) as any as UseReadQuery;

it("returns unknown when TData cannot be inferred", () => {
const query = gql``;

Expand Down Expand Up @@ -4706,7 +4717,7 @@ describe.skip("type tests", () => {
loadQuery({ foo: "bar" });
});

it("optional variables are optional to loadQuery", () => {
it.only("optional variables are optional to loadQuery", () => {
const query: TypedDocumentNode<{ posts: string[] }, { limit?: number }> =
gql``;

Expand All @@ -4715,15 +4726,27 @@ describe.skip("type tests", () => {
loadQuery();
loadQuery({});
loadQuery({ limit: 10 });
loadQuery({
// @ts-expect-error unknown variable
foo: "bar",
});
loadQuery({
limit: 10,
// @ts-expect-error unknown variable
foo: "bar",
});

attest(
loadQuery({
// @ts-expect-error
foo: "bar",
})
).type.errors(
"Object literal may only specify known properties, " +
"and 'foo' does not exist in type '{ limit?: number | undefined; }"
);

attest(
loadQuery({
limit: 10,
// @ts-expect-error
foo: "bar",
})
).type.errors(
"Object literal may only specify known properties, " +
"and 'foo' does not exist in type '{ limit?: number | undefined; }'."
);
});

it("enforces required variables when TVariables includes required variables", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/internal/__tests__/useDeepMemo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("useDeepMemo", () => {
it("returns memoized value when its dependencies are deeply equal", () => {
const { result, rerender } = renderHook(
({ active, items, user }) => {
useDeepMemo(() => ({ active, items, user }), [items, name, active]);
useDeepMemo(() => ({ active, items, user }), [items, user, active]);
},
{
initialProps: {
Expand Down
Loading