Skip to content

Commit

Permalink
feat: 添加typography测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
rayhomie committed Jun 26, 2024
1 parent 67bf17d commit 9ba14bd
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/alipay/Typography/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { getInstance, sleep } from 'tests/utils';
import { describe, expect, it, vi } from 'vitest';
import { ITypographyProps } from '../../../src/Typography/props';

const createTypography = (options: Partial<ITypographyProps>) => {
const my = {
canIUse() {
return true;
},
env: {
platform: 'iOS',
},
};
const instance = getInstance(
'Typography',
{
...options,
},
my
);
return {
instance,
};
};

describe('typography', () => {
it('typography config', () => {
const { instance } = createTypography({});
const { data, props } = instance.getConfig();
expect({ data, props }).toMatchFileSnapshot(
'snapshot/typography_alipay_config.txt'
);
});

it('test tap', async () => {
const onTap = vi.fn();
const catchTap = vi.fn();
const onDisabledTap = vi.fn();
const { instance } = createTypography({
onTap,
catchTap,
onDisabledTap,
});

await instance.callMethod('onTap');
await instance.callMethod('catchTap');
await sleep(10);

expect(catchTap).toBeCalledTimes(1);
expect(onTap).toBeCalledTimes(1);
expect(onDisabledTap).toBeCalledTimes(0);
});

it('disabled 为 true', async () => {
const onTap = vi.fn();
const catchTap = vi.fn();
const onDisabledTap = vi.fn();
const { instance } = createTypography({
disabled: true,
onTap,
catchTap,
onDisabledTap,
});

await instance.callMethod('onTap');
await sleep(10);

expect(catchTap).toBeCalledTimes(0);
expect(onTap).toBeCalledTimes(0);
expect(onDisabledTap).toBeCalledTimes(1);
});
});
17 changes: 17 additions & 0 deletions tests/alipay/Typography/snapshot/typography_alipay_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"data": {
"phonemodel": "",
},
"props": {
"activeClassName": "",
"className": "",
"disabled": false,
"fontWeight": "normal",
"iconPosition": "right",
"lineThrough": false,
"selectable": false,
"style": "",
"text": "",
"underline": false,
},
}

0 comments on commit 9ba14bd

Please sign in to comment.