-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(button)!: remove unnecessary property preventClickDefault
PiperOrigin-RevId: 542958395
- Loading branch information
1 parent
cf5d893
commit 9244524
Showing
2 changed files
with
73 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// import 'jasmine'; (google3-only) | ||
|
||
import {html} from 'lit'; | ||
|
||
import {Environment} from '../testing/environment.js'; | ||
import {createTokenTests} from '../testing/tokens.js'; | ||
|
||
import {MdFilledButton} from './filled-button.js'; | ||
import {ButtonHarness} from './harness.js'; | ||
|
||
describe('<md-filled-button>', () => { | ||
const env = new Environment(); | ||
|
||
describe('.styles', () => { | ||
createTokenTests(MdFilledButton.styles); | ||
}); | ||
|
||
describe('form associated', () => { | ||
async function setupTest() { | ||
const root = | ||
env.render(html`<form><md-filled-button></md-filled-button></form>`); | ||
const element = root.querySelector('md-filled-button'); | ||
if (!element) { | ||
throw new Error(`Could not query rendered <md-filled-button>`); | ||
} | ||
const form = root.querySelector('form'); | ||
if (!form) throw new Error(`Could not query form`); | ||
|
||
await env.waitForStability(); | ||
|
||
return {harness: new ButtonHarness(element), form}; | ||
} | ||
|
||
it('button with type submit can submit a form', async () => { | ||
const {harness, form} = await setupTest(); | ||
harness.element.type = 'submit'; | ||
|
||
spyOn(form, 'requestSubmit'); | ||
spyOn(form, 'reset'); | ||
await harness.clickWithMouse(); | ||
|
||
expect(form.requestSubmit).toHaveBeenCalled(); | ||
expect(form.reset).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('button with type reset can reset a form', async () => { | ||
const {harness, form} = await setupTest(); | ||
harness.element.type = 'reset'; | ||
|
||
spyOn(form, 'requestSubmit'); | ||
spyOn(form, 'reset'); | ||
await harness.clickWithMouse(); | ||
|
||
expect(form.requestSubmit).not.toHaveBeenCalled(); | ||
expect(form.reset).toHaveBeenCalled(); | ||
}); | ||
|
||
it('submit can be cancelled with preventDefault', async () => { | ||
const {harness, form} = await setupTest(); | ||
harness.element.type = 'submit'; | ||
|
||
spyOn(form, 'requestSubmit'); | ||
|
||
harness.element.addEventListener('click', e => { | ||
e.preventDefault(); | ||
}, {once: true}); | ||
|
||
await harness.clickWithMouse(); | ||
|
||
expect(form.requestSubmit).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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