-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify cancel button test case setup.
- Loading branch information
Showing
1 changed file
with
24 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,36 +106,34 @@ describe('SupportForm', () => { | |
}); | ||
}); | ||
|
||
describe('clicking cancel button', () => { | ||
let el: SupportForm; | ||
let emailInput: HTMLInputElement; | ||
let cancelButton: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
el = await fixture( | ||
html` | ||
<support-form></support-form> | ||
` | ||
); | ||
emailInput = el.shadowRoot!.querySelector('mwc-textfield[name="Email"')!; | ||
await setValue(emailInput, '[email protected]'); | ||
cancelButton = el.shadowRoot!.querySelector('mwc-button[label="Cancel"]')!; | ||
}); | ||
it('clicking cancel button resets the form', async () => { | ||
const el: SupportForm = await fixture( | ||
html` | ||
<support-form></support-form> | ||
` | ||
); | ||
const emailInput: HTMLInputElement = el.shadowRoot!.querySelector('mwc-textfield[name="Email"')!; | ||
await setValue(emailInput, '[email protected]'); | ||
|
||
it('resets the form', async () => { | ||
cancelButton.click(); | ||
await nextFrame(); | ||
const cancelButton: HTMLElement = el.shadowRoot!.querySelector('mwc-button[label="Cancel"]')!; | ||
cancelButton.click(); | ||
await nextFrame(); | ||
|
||
expect(emailInput.value).toBe(''); | ||
}); | ||
expect(emailInput.value).toBe(''); | ||
}); | ||
|
||
it('emits form cancel event', async () => { | ||
const listener = oneEvent(el, 'cancel'); | ||
it('emits form cancel event', async () => { | ||
const el: SupportForm = await fixture( | ||
html` | ||
<support-form></support-form> | ||
` | ||
); | ||
const listener = oneEvent(el, 'cancel'); | ||
|
||
cancelButton.click(); | ||
const cancelButton: HTMLElement = el.shadowRoot!.querySelector('mwc-button[label="Cancel"]')!; | ||
cancelButton.click(); | ||
|
||
const {detail} = await listener; | ||
expect(detail).toBeTrue(); | ||
}); | ||
const {detail} = await listener; | ||
expect(detail).toBeTrue(); | ||
}); | ||
}); |