Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Added test utility from SKY UX #382

Merged
merged 3 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions runtime/testing/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './matchers';
export * from './test-module';
export * from './test-utility';
23 changes: 23 additions & 0 deletions runtime/testing/browser/test-utility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export interface SkyAppTestUtilityEventArgs {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd call this SkyAppTestUtilityEventOptions instead. Ending a class name with EventArgs is a common pattern for classes used to pass arguments into an event handler, which is not the case here. I'd also move it to a separate file so we're only exporting one type from this file.

bubbles?: boolean;
cancelable?: boolean;
}

function getWindow() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the purpose of this function. I could see if maybe you wanted to mock out the window object you'd want to do something like this, but it's not possible with the code as it is.

return window;
}

export class SkyAppTestUtility {
public static fireDomEvent(
element: EventTarget,
eventName: string,
args?: SkyAppTestUtilityEventArgs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to change this parameter name to match the new class name.

) {
const defaults = { bubbles: true, cancelable: true };
const options = Object.assign({}, defaults, args);
const event = getWindow().document.createEvent('CustomEvent');

event.initEvent(eventName, options.bubbles, options.cancelable);
element.dispatchEvent(event);
}
}