Skip to content

Commit

Permalink
chore(test): use flush function instead of custom one
Browse files Browse the repository at this point in the history
Before this commit some unit test suites were using custom function to
delay assertions because of the latency of the DOM to be updated by
dom-repeat and dom-if. Now, they are using the function "flush" (that is
provided by web-component-teser?).

See: https://www.polymer-project.org/2.0/docs/tools/tests#hybrid-elements-test-local-dom
  • Loading branch information
masonlouchart committed Sep 4, 2018
1 parent 9821069 commit 03962c7
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions test/login-fire-social_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,20 @@
</test-fixture>

<script>
/**
* Adds delay to a function call. Used for assertions after templates "dom-if"
* and "dom-repeat" restamping. Seems those tempaltes need time for re-redering.
*/
const afterNextRender = (f, delay = 5) => setTimeout(f, delay);

describe('Behavior Audit - Fixture: Default', function() {
let social;

beforeEach(function(done) {
beforeEach(function() {
social = fixture('Default');
afterNextRender(done);
});

it('Should display only "Anonymous" button', function() {
let buttons = (social.shadowRoot || social).querySelectorAll('paper-social-button');
expect(typeof buttons).to.be.Array;
expect(buttons.length).to.be.equal(1);
it('Should display only "Anonymous" button', function(done) {
flush(function() {
let buttons = (social.shadowRoot || social).querySelectorAll('paper-social-button');
expect(typeof buttons).to.be.Array;
expect(buttons.length).to.be.equal(1);
done();
});
});

it('Should have only "Anonymous" provider in its list', function() {
Expand All @@ -69,11 +65,9 @@

it('Should sign-in with the provider associated to the clicked button', function(done) {
social.providers = 'facebook, google, twitter';
afterNextRender(() => {
sinon.stub(social, 'signInOrOut');
flush(function() {
const button = (social.shadowRoot || social).querySelectorAll('paper-social-button')[1];
stub('login-fire-social', {
signInOrOut: null,
});
button.addEventListener('click', function(event) {
expect(social.provider).to.be.equal('google');
expect(social.provider).to.be.equal(event.target.provider.id);
Expand All @@ -85,15 +79,15 @@

it('Should display only a sign-out button when user is signed-in', function(done) {
social.addEventListener('signedin', function() {
afterNextRender(() => {
flush(function() {
expect(social.signedIn).to.be.true;
let buttons = (social.shadowRoot || social).querySelectorAll('paper-social-button');
expect(buttons.length).to.be.equal(1);
expect(buttons[0]._text).to.contain('Sign out');
done();
});
});
(social.shadowRoot || social).querySelector('paper-social-button').click();
social.signInWith('anonymous');
});

it('Should apply attribute "flat" on all buttons', function() {
Expand Down

0 comments on commit 03962c7

Please sign in to comment.