Skip to content

Commit

Permalink
WIP: Add unit test for missing static attachTo() method
Browse files Browse the repository at this point in the history
  • Loading branch information
acdvorak committed Feb 14, 2019
1 parent 3c83f31 commit 5d3f489
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/unit/mdc-auto-init/mdc-auto-init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class FakeComponent {
}
}

class InvalidComponent {
constructor(node) {
this.node = node;
}
}

const createFixture = () => bel`
<div id="root">
<p data-mdc-auto-init="FakeComponent" class="mdc-fake">Fake Element</p>
Expand All @@ -48,6 +54,12 @@ const setupTest = () => {
return createFixture();
};

const setupInvalidTest = () => {
mdcAutoInit.deregisterAll();
mdcAutoInit.register('InvalidComponent', InvalidComponent);
return createFixture();
};

suite('MDCAutoInit');

test('calls attachTo() on components registered for identifier on nodes w/ data-mdc-auto-init attr', () => {
Expand All @@ -57,6 +69,11 @@ test('calls attachTo() on components registered for identifier on nodes w/ data-
assert.isOk(root.querySelector('.mdc-fake').FakeComponent instanceof FakeComponent);
});

test('throws when attachTo() is missing', () => {
const root = setupInvalidTest();
assert.throws(() => mdcAutoInit(root));
});

test('passes the node where "data-mdc-auto-init" was found to attachTo()', () => {
const root = setupTest();
mdcAutoInit(root);
Expand Down

0 comments on commit 5d3f489

Please sign in to comment.