-
Notifications
You must be signed in to change notification settings - Fork 795
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
feat(mock-doc): dispatch blur and focus events #3449
Changes from 6 commits
c26b8b9
46520d7
7410727
dfe472b
801d287
c4f9566
ed29f91
98546e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,49 @@ describe('event', () => { | |
expect(ev.detail).toBe(88); | ||
}); | ||
|
||
it('FocusEvent() requires type', () => { | ||
expect(() => { | ||
// @ts-ignore checking that it throws when not supplied required arguments | ||
new win.FocusEvent(); | ||
}).toThrow(); | ||
}); | ||
|
||
const focusEventTypes: ('blur' | 'focus')[] = ['blur', 'focus']; | ||
it.each(focusEventTypes)('creates a %s-type MockFocusEvent', (focusType) => { | ||
const ev = new win.FocusEvent(focusType); | ||
expect(ev.bubbles).toBe(false); | ||
expect(ev.cancelBubble).toBe(false); | ||
expect(ev.cancelable).toBe(false); | ||
expect(ev.composed).toBe(false); | ||
expect(ev.currentTarget).toBe(null); | ||
expect(ev.defaultPrevented).toBe(false); | ||
expect(ev.srcElement).toBe(null); | ||
expect(ev.target).toBe(null); | ||
expect(typeof ev.timeStamp).toBe('number'); | ||
expect(ev.type).toBe(focusType); | ||
expect(ev.relatedTarget).toBe(null); | ||
}); | ||
|
||
it('FocusEvent(type, focusEventInitDic)', () => { | ||
const focusEventInitDic = { | ||
bubbles: true, | ||
composed: true, | ||
relatedTarget: null as EventTarget | null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be good to have a test where we pass a legit value through for this field, what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what you mean by legit value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry should have been more explicit! just something that matches the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked into this and it doesn't look like any of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok no worries, let's leave it as-is then |
||
}; | ||
const ev = new win.FocusEvent('blur', focusEventInitDic); | ||
expect(ev.bubbles).toBe(true); | ||
expect(ev.cancelBubble).toBe(false); | ||
expect(ev.cancelable).toBe(false); | ||
expect(ev.composed).toBe(true); | ||
expect(ev.currentTarget).toBe(null); | ||
expect(ev.defaultPrevented).toBe(false); | ||
expect(ev.srcElement).toBe(null); | ||
expect(ev.target).toBe(null); | ||
expect(typeof ev.timeStamp).toBe('number'); | ||
expect(ev.type).toBe('blur'); | ||
expect(ev.relatedTarget).toBe(null); | ||
}); | ||
|
||
it('KeyboardEvent() requires type', () => { | ||
expect(() => { | ||
// @ts-ignore checking that it throws when not supplied required arguments | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not crucial, but could we type
type
here as"blur" | "focus"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just waiting on this change, and then it looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So sorry I missed that one! Just committed