Skip to content

Commit

Permalink
chore: reduce flakiness around asserting Shadow DOM content
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlafroscia committed Aug 8, 2019
1 parent b258588 commit 86d6601
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
import { click, find, render, clearRender } from '@ember/test-helpers';
import {
findInShadowRoot,
getShadowRoot,
nextRAF
getShadowRoot
} from 'ember-cli-stencil/test-support';
import hbs from 'htmlbars-inline-precompile';
import td from 'testdouble';
Expand Down Expand Up @@ -44,12 +43,17 @@ module('generating ember components', function(hooks) {
const el = await find('demo-passing-props');
const shadowRoot = await getShadowRoot(el);

assert.equal(shadowRoot.textContent, 'foo', 'Has the initial text');
await assert.convergeOn(
() => shadowRoot.textContent === 'foo',
'Has the initial text'
);

this.set('text', 'bar');
await nextRAF();

assert.equal(shadowRoot.textContent, 'bar', 'Has the updated text value');
await assert.convergeOn(
() => shadowRoot.textContent === 'bar',
'Has the updated text value'
);
});

test('binding complex props', async function(assert) {
Expand All @@ -62,12 +66,11 @@ module('generating ember components', function(hooks) {
const el = await find('demo-rich-props');
const shadowRoot = await getShadowRoot(el);

assert.equal(shadowRoot.textContent, 'foobar');
await assert.convergeOn(() => shadowRoot.textContent === 'foobar');

this.set('list', ['foo', 'bar', 'baz']);
await nextRAF();

assert.equal(shadowRoot.textContent, 'foobarbaz');
await assert.convergeOn(() => shadowRoot.textContent === 'foobarbaz');
});
});

Expand Down
16 changes: 10 additions & 6 deletions packages/ember-cli-stencil/tests/integration/passing-props-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
import { click, find, render } from '@ember/test-helpers';
import {
findInShadowRoot,
getShadowRoot,
nextRAF
getShadowRoot
} from 'ember-cli-stencil/test-support';
import hbs from 'htmlbars-inline-precompile';
import td from 'testdouble';
Expand All @@ -18,7 +17,7 @@ module('passing props', function(hooks) {
const el = await find('demo-passing-props');
const shadowRoot = await getShadowRoot(el);

assert.equal(shadowRoot.textContent, 'Foobar');
await assert.convergeOn(() => shadowRoot.textContent === 'Foobar');
});

test('passing a dynamic property into a component', async function(assert) {
Expand All @@ -30,12 +29,17 @@ module('passing props', function(hooks) {
const el = await find('demo-passing-props');
const shadowRoot = await getShadowRoot(el);

assert.equal(shadowRoot.textContent, 'foo', 'Has the initial text');
await assert.convergeOn(
() => shadowRoot.textContent === 'foo',
'Has the initial text'
);

this.set('text', 'bar');
await nextRAF();

assert.equal(shadowRoot.textContent, 'bar', 'Has the updated text value');
await assert.convergeOn(
() => shadowRoot.textContent === 'bar',
'Has the updated text value'
);
});

test('passing a function as a property', async function(assert) {
Expand Down
22 changes: 20 additions & 2 deletions packages/ember-cli-stencil/tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import QUnit from 'qunit';
import { setApplication, waitUntil } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';

import 'ember-cli-testdouble-qunit';

setApplication(Application.create(config.APP));

start();

QUnit.extend(QUnit.assert, {
async convergeOn(condition, message) {
try {
await waitUntil(condition);

this.pushResult({ result: true, message });
} catch (e) {
if (e.message === 'waitUntil timed out') {
this.pushResult({ result: false, message });
} else {
throw e;
}
}
}
});

0 comments on commit 86d6601

Please sign in to comment.