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

chore: fix type warning for unit test file #393

Merged
merged 1 commit into from
Jan 8, 2024
Merged
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
22 changes: 11 additions & 11 deletions components/CheckboxGroup/__test__/checkbox-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ describe('Test: KCheckboxGroup', () => {
await tick();
expect(instance).toBeTruthy();
const smEls = host.querySelector('#group-sm');
expect(smEls.querySelectorAll('.k-checkbox--sm').length).toBe(3);
expect(smEls!.querySelectorAll('.k-checkbox--sm').length).toBe(3);
const mdEls = host.querySelector('#group-md');
expect(mdEls.querySelectorAll('.k-checkbox--md').length).toBe(5);
expect(mdEls!.querySelectorAll('.k-checkbox--md').length).toBe(5);
const lgEls = host.querySelector('#group-lg');
expect(lgEls.querySelectorAll('.k-checkbox--lg').length).toBe(2);
expect(lgEls!.querySelectorAll('.k-checkbox--lg').length).toBe(2);
expect(host.innerHTML).matchSnapshot();
});

Expand All @@ -75,8 +75,8 @@ describe('Test: KCheckboxGroup', () => {
expect(inputEls[0].value === 'false').toBeTruthy();
expect(inputEls[1].value === 'false').toBeTruthy();
expect(inputEls[2].value === 'true').toBeTruthy();
const btn = host.querySelector('#group_change_btn');
btn.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
const btn = host.querySelector('#group_change_btn') as HTMLElement;
btn!.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
await tick();
expect(inputEls[0].value === 'true').toBeTruthy();
expect(inputEls[1].value === 'false').toBeTruthy();
Expand Down Expand Up @@ -140,8 +140,8 @@ describe('Test: KCheckboxGroup', () => {
expect(inputEls[0].value === 'false').toBeTruthy();
expect(inputEls[1].value === 'false').toBeTruthy();
expect(inputEls[2].value === 'true').toBeTruthy();
const btn = host.querySelector('#group_change_disabled_btn');
btn.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
const btn = host.querySelector('#group_change_disabled_btn') as HTMLElement;
btn!.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
await tick();
expect(inputEls[0].value === 'false').toBeTruthy();
expect(inputEls[1].value === 'false').toBeTruthy();
Expand Down Expand Up @@ -190,15 +190,15 @@ describe('Test: KCheckboxGroup', () => {
expect(inputEls[0].value === 'false').toBeTruthy();
expect(inputEls[1].value === 'false').toBeTruthy();
expect(inputEls[2].value === 'true').toBeTruthy();
const btn = host.querySelector('#group_change_value_btn');
btn.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
const btn = host.querySelector('#group_change_value_btn') as HTMLElement;
btn!.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
await tick();
expect(inputEls[0].value === 'false').toBeTruthy();
expect(inputEls[1].value === 'false').toBeTruthy();
expect(inputEls[2].value === 'true').toBeTruthy();

const btn2 = host.querySelector('#group_change_disabled_btn');
btn2.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
const btn2 = host.querySelector('#group_change_disabled_btn') as HTMLElement;
btn2!.click(); // or btn.dispatchEvent(new window.Event('click', { bubbles: true }))
await tick();
expect(inputEls[0].value === 'true').toBeTruthy();
expect(inputEls[1].value === 'false').toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions components/Contextmenu/__test__/contextmenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Test: KContextmenu', () => {
expect(host.innerHTML.includes('<span>contextmenu-sub-title</span>')).toBeTruthy();
expect(host.innerHTML.includes('options 4')).not.toBeTruthy();
const submenu = host.querySelector('.k-contextmenu-sub-menu--base');
submenu.dispatchEvent(new Event('mouseenter', { cancelable: true }));
submenu!.dispatchEvent(new Event('mouseenter', { cancelable: true }));
await tick();
await vi.advanceTimersByTimeAsync(300);
expect(host.innerHTML.includes('options 4')).toBeTruthy();
Expand All @@ -122,7 +122,7 @@ describe('Test: KContextmenu', () => {
expect(host.innerHTML.includes('options 4')).not.toBeTruthy();
expect(host.innerHTML.includes('k-contextmenu-sub-menu__disabled')).toBeTruthy();
const submenu = host.querySelector('.k-contextmenu-sub-menu--base');
submenu.dispatchEvent(new Event('mouseenter', { cancelable: true }));
submenu!.dispatchEvent(new Event('mouseenter', { cancelable: true }));
await tick();
await vi.advanceTimersByTimeAsync(300);
expect(host.innerHTML.includes('options 4')).not.toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions components/Descriptions/__test__/descriptions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Test: KDescriptions', () => {
expect(instance).toBeTruthy();
await tick();
const titleEl = host.querySelector('#slot-title');
expect(titleEl.textContent).toBe('Ikun Descriptions Title');
expect(titleEl!.textContent).toBe('Ikun Descriptions Title');
expect(host.innerHTML).matchSnapshot();
});

Expand All @@ -146,7 +146,7 @@ describe('Test: KDescriptions', () => {
expect(instance).toBeTruthy();
await tick();
const extraEl = host.querySelector('#slot-extra');
expect(extraEl.textContent).toBe('Ikun Descriptions Extra');
expect(extraEl!.textContent).toBe('Ikun Descriptions Extra');
expect(host.innerHTML).matchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Test: KDescriptionsItem', () => {
expect(instance).toBeTruthy();
expect((host as HTMLElement)!.innerHTML.includes('k-descriptions-item--label')).toBeTruthy();
const labelEl = host.querySelector('.k-descriptions-item--label');
expect(labelEl.textContent).toBe('KDescriptionsItem');
expect(labelEl!.textContent).toBe('KDescriptionsItem');
expect(host.innerHTML).matchSnapshot();
});

Expand All @@ -51,7 +51,7 @@ describe('Test: KDescriptionsItem', () => {
expect(instance).toBeTruthy();
await tick();
const labelEl = host.querySelector('#slot-label');
expect(labelEl.textContent).toBe('Ikun Descriptions Item Label');
expect(labelEl!.textContent).toBe('Ikun Descriptions Item Label');
expect(host.innerHTML).matchSnapshot();
});
});
4 changes: 2 additions & 2 deletions components/Ellipsis/__test__/ellipsis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Test: KEllipsis', () => {
});
expect(instance).toBeTruthy();
const elm = host.querySelector('[slot="triggerEl"]');
elm.dispatchEvent(new Event('mouseenter', { bubbles: true }));
elm!.dispatchEvent(new Event('mouseenter', { bubbles: true }));
await tick();
await vi.advanceTimersByTimeAsync(300);
expect(document.body.innerHTML.includes('我言秋日胜春朝')).toBeTruthy();
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Test: KEllipsis', () => {
}
});
expect(instance).toBeTruthy();
const elm = host.querySelector('[slot="triggerEl"]');
const elm = host.querySelector('[slot="triggerEl"]') as HTMLElement;
expect(elm.style.display === '-webkit-inline-box').toBeTruthy();
elm.dispatchEvent(new Event('click', { bubbles: true }));
await tick();
Expand Down
8 changes: 4 additions & 4 deletions components/Icon/__test__/icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe('Test: KIcon', () => {
}
});
expect(instance).toBeTruthy();
expect(host.children[0].style.width).toBe('30px');
expect(host.children[0].style.height).toBe('30px');
expect((host.children[0] as HTMLElement).style.width).toBe('30px');
expect((host.children[0] as HTMLElement).style.height).toBe('30px');
expect(host.innerHTML).matchSnapshot();
});

Expand All @@ -87,7 +87,7 @@ describe('Test: KIcon', () => {
value = v.detail;
mockFn();
});
const input = host.children[0];
const input = host.children[0] as HTMLElement;
input.click(); // or input.dispatchEvent(new window.Event('click', { bubbles: true }))
await tick();
expect(instance).toBeTruthy();
Expand All @@ -100,7 +100,7 @@ describe('Test: KIcon', () => {
target: host
});
expect(instance).toBeTruthy();
expect(host.children[0].style.background).toBe('red');
expect((host.children[0] as HTMLElement).style.background).toBe('red');
expect(host.innerHTML).matchSnapshot();
});
});
2 changes: 1 addition & 1 deletion components/Mask/__test__/mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Test: KMask', () => {
}
});
expect(instance).toBeTruthy();
expect(host.children[0]!.style.backgroundColor).toBe('red');
expect((host.children[0] as HTMLElement)!.style.backgroundColor).toBe('red');
expect(host.innerHTML).matchSnapshot();
});
});
Expand Down
2 changes: 1 addition & 1 deletion components/MessageBox/__test__/msg-box.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe('Test: KMsgBox', () => {
expect(rV).toBe(false);
expect(vV).toBe('bar');

input[0].value = 1;
input[0].value = '1';
input[0].dispatchEvent(new window.Event('input', { bubbles: true }));
await tick();
btns[1].click();
Expand Down
6 changes: 3 additions & 3 deletions components/Modal/__test__/modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Test: KModal', () => {
await tick();
instance.$on('cancel', mockFn);
const btn = host.querySelector('.k-button--info__fill');
btn.dispatchEvent(new Event('click', { bubbles: true }));
btn!.dispatchEvent(new Event('click', { bubbles: true }));
await tick();
expect(instance).toBeTruthy();
expect(mockFn).toBeCalled();
Expand All @@ -127,7 +127,7 @@ describe('Test: KModal', () => {
await tick();
instance.$on('confirm', mockFn);
const btn = host.querySelector('.k-button--primary__fill');
btn.dispatchEvent(new Event('click', { bubbles: true }));
btn!.dispatchEvent(new Event('click', { bubbles: true }));
await tick();
expect(instance).toBeTruthy();
expect(mockFn).toBeCalled();
Expand All @@ -145,7 +145,7 @@ describe('Test: KModal', () => {
await tick();
instance.$on('close', mockFn);
const btn = host.querySelector('.i-carbon-close');
btn.dispatchEvent(new Event('click', { bubbles: true }));
btn!.dispatchEvent(new Event('click', { bubbles: true }));
await tick();
expect(instance).toBeTruthy();
expect(mockFn).toBeCalled();
Expand Down
Loading