Skip to content

Commit

Permalink
test: 测试案例报错
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed May 17, 2024
1 parent adc8cb0 commit 349ff22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions src/cascader/__test__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,26 @@ describe('cascader', () => {
});

describe('events', () => {
it(': close', async () => {
it(': close trigger closeBtn', async () => {
const onClose = vi.fn();
const wrapper = mount(<Cascader options={options} onClose={onClose} />);
const $closeBtn = wrapper.find(`.${name}__close-btn`);
await $closeBtn.trigger('click');
expect(onClose).toHaveBeenCalledTimes(1);
expect(onClose).toHaveBeenLastCalledWith({ trigger: 'close-btn' });
expect(onClose).toHaveBeenLastCalledWith('close-btn');


});

it(': close trigger overlay', async () => {
const onClose = vi.fn();
const wrapper = mount(<Cascader options={options} onClose={onClose} visible={true}/>);
// overlay
const $overlay = wrapper.find(`.${prefix}-overlay`);
const $overlay = wrapper.find(`.${prefix}-overlay--active`);
expect($overlay.exists()).toBeTruthy()
$overlay.trigger('click');
expect(onClose).toBeCalledTimes(2);
expect(onClose).toHaveBeenLastCalledWith({ trigger: 'overlay' });
expect(onClose).toBeCalledTimes(1);
expect(onClose).toHaveBeenLastCalledWith('overlay');
});

it(': pick', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/cascader/cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import TdCascaderProps from './props';
import { useVModel } from '../shared';
import { TreeOptionData } from '../common';
import { useConfig } from '../config-provider/useConfig';
import { useTNodeJSX } from '@/hooks/tnode';
import { usePrefixClass } from '@/hooks/useClass';
import { useTNodeJSX } from '../hooks/tnode';
import { usePrefixClass } from '../hooks/useClass';
import { TriggerSource } from './type';

const { prefix } = config;
Expand Down Expand Up @@ -66,7 +66,7 @@ export default defineComponent({
const steps = reactive([placeholder.value]);

const initWithValue = () => {
if (value.value != null) {
if (cascaderValue.value != null) {
steps.pop();
const path = getIndexesByValue(props.options, value.value);
path?.forEach((e: number) => {
Expand Down

0 comments on commit 349ff22

Please sign in to comment.