Skip to content

Commit 68e3376

Browse files
DrJKLampcode-com
andcommitted
fix: clean up sign-in form tests and loading state
- Remove per-test ProgressSpinner stub; stub globally in mountComponent - Use findComponent(ProgressSpinner) consistently in loading tests - Replace non-null assertion with throwing guard in findForgotPasswordButton Amp-Thread-ID: https://ampcode.com/threads/T-019c7f35-4320-75dc-be40-98526259f2ae Co-authored-by: Amp <amp@ampcode.com>
1 parent d91a1e8 commit 68e3376

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

src/components/dialog/content/signin/SignInForm.test.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ describe('SignInForm', () => {
7676

7777
return mount(SignInForm, {
7878
global: {
79-
plugins: [PrimeVue, i18n, ToastService]
79+
plugins: [PrimeVue, i18n, ToastService],
80+
stubs: { ProgressSpinner: true }
8081
},
8182
props,
8283
...options
@@ -85,11 +86,13 @@ describe('SignInForm', () => {
8586

8687
describe('Forgot Password Link', () => {
8788
function findForgotPasswordButton(wrapper: VueWrapper<ComponentInstance>) {
88-
return wrapper
89+
const btn = wrapper
8990
.findAll('button[type="button"]')
9091
.find((btn) =>
9192
btn.text().includes(enMessages.auth.login.forgotPassword)
92-
)!
93+
)
94+
if (!btn) throw new Error('Forgot password button not found')
95+
return btn
9396
}
9497

9598
it('shows disabled style when email is empty', async () => {
@@ -151,28 +154,10 @@ describe('SignInForm', () => {
151154
describe('Loading State', () => {
152155
it('shows spinner when loading', async () => {
153156
mockLoading = true
154-
const wrapper = mountComponent(
155-
{},
156-
{
157-
global: {
158-
plugins: [
159-
PrimeVue,
160-
createI18n({
161-
legacy: false,
162-
locale: 'en',
163-
messages: { en: enMessages }
164-
}),
165-
ToastService
166-
],
167-
stubs: {
168-
ProgressSpinner: { template: '<div data-testid="spinner" />' }
169-
}
170-
}
171-
}
172-
)
157+
const wrapper = mountComponent()
173158
await nextTick()
174159

175-
expect(wrapper.find('[data-testid="spinner"]').exists()).toBe(true)
160+
expect(wrapper.findComponent(ProgressSpinner).exists()).toBe(true)
176161
expect(wrapper.find('button[type="submit"]').exists()).toBe(false)
177162
})
178163

0 commit comments

Comments
 (0)