@open-wc/testing-helpers
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.2.0](https://github.com/open-wc/open-wc/tree/master/packages/testing-helpers/compare/@open-wc/testing-helpers@0.1.2...@open-wc/testing-helpers@0.2.0) (2018-11-15) | ||
### Features | ||
* simplify testing-helpers names ([68e1cb5](https://github.com/open-wc/open-wc/tree/master/packages/testing-helpers/commit/68e1cb5)) | ||
## [0.1.2](https://github.com/open-wc/open-wc/tree/master/packages/testing-helpers/compare/@open-wc/testing-helpers@0.1.1...@open-wc/testing-helpers@0.1.2) (2018-11-05) | ||
@@ -8,0 +19,0 @@ |
@@ -0,1 +1,3 @@ | ||
let defineCECounter = 0; | ||
/** | ||
@@ -6,6 +8,6 @@ * Registers a new element with an automatically generated unique name. | ||
* @example | ||
* const tag = registerUniqueElement(class extends MyMixin(HTMLElement) { | ||
* const tag = defineCE(class extends MyMixin(HTMLElement) { | ||
* // define custom element class body | ||
* }); | ||
* const el = htmlFixture(`<${tag}></${tag}>`); | ||
* const el = fixture(`<${tag}></${tag}>`); | ||
* // test el | ||
@@ -16,7 +18,7 @@ * | ||
*/ | ||
export function registerUniqueElement(klass) { | ||
const uniqueNumberString = `${Date.now()}${Math.random()}`.replace('.', ''); | ||
const name = `test-${uniqueNumberString}`; | ||
customElements.define(name, klass); | ||
return name; | ||
export function defineCE(klass) { | ||
const tag = `test-${defineCECounter}`; | ||
customElements.define(tag, klass); | ||
defineCECounter += 1; | ||
return tag; | ||
} | ||
@@ -39,3 +41,3 @@ | ||
*/ | ||
export async function timeoutAsync(ms) { | ||
export async function aTimeout(ms) { | ||
return new Promise((resolve) => { | ||
@@ -52,6 +54,6 @@ setTimeout(resolve, ms); | ||
*/ | ||
export async function blurTrigger(element) { | ||
export async function triggerBlurFor(element) { | ||
element.blur(); | ||
if (isIE()) { | ||
await timeoutAsync(); | ||
await aTimeout(); | ||
} | ||
@@ -66,6 +68,6 @@ } | ||
*/ | ||
export async function focusTrigger(element) { | ||
export async function triggerFocusFor(element) { | ||
element.focus(); | ||
if (isIE()) { | ||
await timeoutAsync(); | ||
await aTimeout(); | ||
} | ||
@@ -81,6 +83,6 @@ } | ||
*/ | ||
export async function eventTrigger(element, eventName) { | ||
export async function oneEvent(element, eventName) { | ||
return new Promise((resolve) => { | ||
function listener(event) { | ||
resolve(event); | ||
function listener(ev) { | ||
resolve(ev); | ||
element.removeEventListener(eventName, listener); | ||
@@ -92,5 +94,10 @@ } | ||
export async function nextFrame() { | ||
return new Promise(resolve => requestAnimationFrame(resolve)); | ||
} | ||
/** | ||
* Resolves after flush. | ||
* Useful in async tests with await keyword. | ||
* DEPRECATED: | ||
* Only useful with WCT pls use nextFrame as an alternative. | ||
* If used not within WCT it will fallback to a timout of 2ms. | ||
* | ||
@@ -97,0 +104,0 @@ * @returns {Promise<void>} |
export { html, unsafeStatic } from './lit-html.js'; | ||
export { | ||
blurTrigger, focusTrigger, eventTrigger, isIE, registerUniqueElement, timeoutAsync, | ||
triggerBlurFor, triggerFocusFor, oneEvent, isIE, defineCE, aTimeout, nextFrame, | ||
} from './helpers.js'; | ||
export { litHtmlFixture, litHtmlFixtureSync } from './litHtmlFixture.js'; | ||
export { htmlFixture, htmlFixtureSync } from './htmlFixture.js'; | ||
export { litFixture, litFixtureSync } from './litFixture.js'; | ||
export { fixture, fixtureSync } from './fixture.js'; |
{ | ||
"name": "@open-wc/testing-helpers", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Testing Helpers following open-wc recommendations", | ||
@@ -28,3 +28,3 @@ "author": "open-wc", | ||
}, | ||
"gitHead": "fd4d41a55acc83e35293d060e41584ca8db06fe9" | ||
"gitHead": "f2c473565f06dc2a5cb4a3902694480f16347906" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237
11112
9