Skip to content

Commit

Permalink
add an example test
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed May 3, 2024
1 parent cd3b6fd commit 403f477
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/waku/tests/create-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, vi, describe, it, beforeEach, assert } from 'vitest';
import type { MockedFunction } from 'vitest';
import { createPages } from '../src/router/create-pages.js';
import type {
CreatePage,
PathWithoutSlug,
PathWithSlug,
PathWithWildcard,
Expand Down Expand Up @@ -37,6 +38,23 @@ expectType<PathWithWildcard<'/test/[slug]/[...path]', 'slug', 'path'>>(
);

// TODO: type tests for CreatePage and CreateLayout
describe('type tests', () => {
it('CreatePage', () => {
const createPage: CreatePage = vi.fn();
// @ts-expect-error: render is not valid
createPage({ render: 'foo' });
// @ts-expect-error: path is required
createPage({ render: 'static' });
// @ts-expect-error: path is invalid
createPage({ render: 'static', path: 'bar' });
// @ts-expect-error: component is missing
createPage({ render: 'static', path: '/' });
// @ts-expect-error: component is not a function
createPage({ render: 'static', path: '/', component: 123 });
// good
createPage({ render: 'static', path: '/', component: () => 'Hello' });
});
});

const defineRouterMock = unstable_defineRouter as MockedFunction<
typeof unstable_defineRouter
Expand Down

0 comments on commit 403f477

Please sign in to comment.