From 5d3f489c2b9898356da5337a2a60584007b58960 Mon Sep 17 00:00:00 2001 From: Andy Dvorak Date: Thu, 14 Feb 2019 10:59:08 -0800 Subject: [PATCH] WIP: Add unit test for missing static `attachTo()` method --- test/unit/mdc-auto-init/mdc-auto-init.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/unit/mdc-auto-init/mdc-auto-init.test.js b/test/unit/mdc-auto-init/mdc-auto-init.test.js index c531ab266ba..9347f078a4b 100644 --- a/test/unit/mdc-auto-init/mdc-auto-init.test.js +++ b/test/unit/mdc-auto-init/mdc-auto-init.test.js @@ -36,6 +36,12 @@ class FakeComponent { } } +class InvalidComponent { + constructor(node) { + this.node = node; + } +} + const createFixture = () => bel`

Fake Element

@@ -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', () => { @@ -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);