Skip to content

Commit

Permalink
test: update API plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung committed Dec 3, 2021
1 parent f42e595 commit 6f8e6d3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
48 changes: 32 additions & 16 deletions packages/plugin-dumi-api/__tests__/API.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,44 @@ import React from 'react';
import { render } from '@testing-library/react';
import API from '../src/API';

jest.mock('@@/dumi/apis', () => {
jest.mock('dumi/theme', function () {
return {
Hello: {
default: [
{
identifier: 'className',
description: 'Extra CSS className for this component',
'description.zh-CN': '组件额外的 CSS className',
type: 'string',
context: {
locale: '',
config: {
locales: [],
},
apis: {
Hello: {
default: [
{
identifier: 'className',
description: 'Extra CSS className for this component',
'description.zh-CN': '组件额外的 CSS className',
type: 'string',
},
{
identifier: 'type',
description: "I'm required",
'description.zh-CN': '我是一个必选属性',
type: 'string',
required: true,
},
],
},
{
identifier: 'type',
description: "I'm required",
'description.zh-CN': '我是一个必选属性',
type: 'string',
required: true,
},
],
},
},
};
});

jest.mock('react', function () {
const originalModule = jest.requireActual('react');
return {
...originalModule,
useContext: jest.fn(context => context),
};
});

describe('API component', () => {
test('Match snapshot', () => {
const { asFragment } = render(<API hideTitle={false} identifier="Hello" export="default" />);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dumi-api/src/useApiData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect, useContext } from 'react';
import context from '@umijs/preset-dumi/lib/theme/context';
import { context } from 'dumi/theme';
import type { AtomPropsDefinition } from 'dumi-assets-types';
import type { IApiDefinition } from './parser';
/**
Expand Down
4 changes: 3 additions & 1 deletion packages/preset-dumi/src/theme/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import type { IConfig, IRoute } from '@umijs/types';
import type { INav } from '../routes/getNavFromRoutes';
import type { IMenu } from '../routes/getMenuFromRoutes';
import type { ILocale } from '../routes/getLocaleFromRoutes';
import type { IApiDefinition } from '@umijs/plugin-dumi-api/lib/parser';
import type { IDumiOpts } from '..';
import type { IPreviewerComponentProps } from '.';
import type { AtomPropsDefinition } from 'dumi-assets-types';

export type IApiDefinition = AtomPropsDefinition;

export interface IThemeContext {
/**
Expand Down

0 comments on commit 6f8e6d3

Please sign in to comment.