From 28e048f388bbfbcb3aa138ab3cdafe3c862f231c Mon Sep 17 00:00:00 2001 From: Elliott Marquez Date: Tue, 20 Aug 2019 19:48:54 -0700 Subject: [PATCH] ts-ify tests --- package-lock.json | 12 +++-- package.json | 2 + test/tsconfig.json | 3 +- ...{mwc-button.test.js => mwc-button.test.ts} | 0 test/unit/mwc-card.test.js | 35 ------------- ...-checkbox.test.js => mwc-checkbox.test.ts} | 2 +- test/unit/mwc-chips.test.js | 51 ------------------- test/unit/mwc-dialog.test.js | 35 ------------- .../unit/{mwc-fab.test.js => mwc-fab.test.ts} | 4 +- ...ormfield.test.js => mwc-formfield.test.ts} | 0 ...button.test.js => mwc-icon-button.test.ts} | 29 +++++++++-- .../{mwc-icon.test.js => mwc-icon.test.ts} | 0 ...ss.test.js => mwc-linear-progress.test.ts} | 0 test/unit/mwc-list.test.js | 51 ------------------- test/unit/mwc-menu.test.js | 35 ------------- .../{mwc-radio.test.js => mwc-radio.test.ts} | 0 ...{mwc-ripple.test.js => mwc-ripple.test.ts} | 0 ...{mwc-select.test.js => mwc-select.test.ts} | 0 ...-snackbar.test.js => mwc-snackbar.test.ts} | 0 ...{mwc-switch.test.js => mwc-switch.test.ts} | 2 +- .../{mwc-tabs.test.js => mwc-tabs.test.ts} | 0 ...extfield.test.js => mwc-textfield.test.ts} | 4 +- test/unit/mwc-typography.test.js | 25 --------- 23 files changed, 44 insertions(+), 246 deletions(-) rename test/unit/{mwc-button.test.js => mwc-button.test.ts} (100%) delete mode 100644 test/unit/mwc-card.test.js rename test/unit/{mwc-checkbox.test.js => mwc-checkbox.test.ts} (98%) delete mode 100644 test/unit/mwc-chips.test.js delete mode 100644 test/unit/mwc-dialog.test.js rename test/unit/{mwc-fab.test.js => mwc-fab.test.ts} (100%) rename test/unit/{mwc-formfield.test.js => mwc-formfield.test.ts} (100%) rename test/unit/{mwc-icon-button.test.js => mwc-icon-button.test.ts} (90%) rename test/unit/{mwc-icon.test.js => mwc-icon.test.ts} (100%) rename test/unit/{mwc-linear-progress.test.js => mwc-linear-progress.test.ts} (100%) delete mode 100644 test/unit/mwc-list.test.js delete mode 100644 test/unit/mwc-menu.test.js rename test/unit/{mwc-radio.test.js => mwc-radio.test.ts} (100%) rename test/unit/{mwc-ripple.test.js => mwc-ripple.test.ts} (100%) rename test/unit/{mwc-select.test.js => mwc-select.test.ts} (100%) rename test/unit/{mwc-snackbar.test.js => mwc-snackbar.test.ts} (100%) rename test/unit/{mwc-switch.test.js => mwc-switch.test.ts} (98%) rename test/unit/{mwc-tabs.test.js => mwc-tabs.test.ts} (100%) rename test/unit/{mwc-textfield.test.js => mwc-textfield.test.ts} (90%) delete mode 100644 test/unit/mwc-typography.test.js diff --git a/package-lock.json b/package-lock.json index 094a15e8d..5b5d13784 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2106,9 +2106,9 @@ } }, "@types/chai": { - "version": "4.1.7", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz", - "integrity": "sha512-2Y8uPt0/jwjhQ6EiluT0XCri1Dbplr0ZxfFXUz+ye13gaqE8u5gL5ppao1JrUYr9cIip5S6MvQzBS7Kke7U9VA==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.0.tgz", + "integrity": "sha512-zw8UvoBEImn392tLjxoavuonblX/4Yb9ha4KBU10FirCfwgzhKO0dvyJSF9ByxV1xK1r2AgnAi/tvQaLgxQqxA==", "dev": true }, "@types/chai-as-promised": { @@ -2438,6 +2438,12 @@ "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", "dev": true }, + "@types/mocha": { + "version": "5.2.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.7.tgz", + "integrity": "sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==", + "dev": true + }, "@types/mz": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/mz/-/mz-0.0.29.tgz", diff --git a/package.json b/package.json index 1ac28ba05..0dcb93ced 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,10 @@ "watch:tests": "npm run build && tsc --build test/tsconfig.json -w & tsc --build test/tsconfig-node.json -w" }, "devDependencies": { + "@types/chai": "^4.2.0", "@types/command-line-args": "^5.0.0", "@types/command-line-usage": "^5.0.1", + "@types/mocha": "^5.2.7", "@typescript-eslint/eslint-plugin": "^1.12.0", "@typescript-eslint/parser": "^1.12.0", "@webcomponents/webcomponentsjs": "^2.2.8", diff --git a/test/tsconfig.json b/test/tsconfig.json index 5158f34c5..4a7cf5aa1 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -6,7 +6,8 @@ "tsBuildInfoFile": ".tsbuildinfo", }, "include": [ - "benchmark/**/*.ts" + "benchmark/**/*.ts", + "unit/**/*.ts" ], "exclude": [ "benchmark/cli.ts" diff --git a/test/unit/mwc-button.test.js b/test/unit/mwc-button.test.ts similarity index 100% rename from test/unit/mwc-button.test.js rename to test/unit/mwc-button.test.ts diff --git a/test/unit/mwc-card.test.js b/test/unit/mwc-card.test.js deleted file mode 100644 index 9a97a6875..000000000 --- a/test/unit/mwc-card.test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {assert} from 'chai'; -import {Card} from '@material/mwc-card'; - -let element; - -suite('mwc-card'); - -beforeEach(() => { - element = document.createElement('mwc-card'); - document.body.appendChild(element); -}); - -afterEach(() => { - document.body.removeChild(element); -}); - -test('initializes as an mwc-button', () => { - assert.instanceOf(element, Card); -}); \ No newline at end of file diff --git a/test/unit/mwc-checkbox.test.js b/test/unit/mwc-checkbox.test.ts similarity index 98% rename from test/unit/mwc-checkbox.test.js rename to test/unit/mwc-checkbox.test.ts index 507a9bb95..e6e1e36b6 100644 --- a/test/unit/mwc-checkbox.test.js +++ b/test/unit/mwc-checkbox.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {assert} from 'chai'; +import {assert, expect} from 'chai'; import {fake} from 'sinon'; import {Checkbox} from '@material/mwc-checkbox'; diff --git a/test/unit/mwc-chips.test.js b/test/unit/mwc-chips.test.js deleted file mode 100644 index e21f742a9..000000000 --- a/test/unit/mwc-chips.test.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {assert} from 'chai'; -import {Chip} from '@material/mwc-chips/mwc-chip.js'; -import {ChipSet} from '@material/mwc-chips/mwc-chip-set.js'; - -let element; - -suite('mwc-chip'); - -beforeEach(() => { - element = document.createElement('mwc-chip'); - document.body.appendChild(element); -}); - -afterEach(() => { - document.body.removeChild(element); -}); - -test('initializes as an mwc-chip', () => { - assert.instanceOf(element, Chip); -}); - -suite('mwc-chip-set'); - -beforeEach(() => { - element = document.createElement('mwc-chip-set'); - document.body.appendChild(element); -}); - -afterEach(() => { - document.body.removeChild(element); -}); - -test('initializes as an mwc-chip-set', () => { - assert.instanceOf(element, ChipSet); -}); \ No newline at end of file diff --git a/test/unit/mwc-dialog.test.js b/test/unit/mwc-dialog.test.js deleted file mode 100644 index 8756c050b..000000000 --- a/test/unit/mwc-dialog.test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {assert} from 'chai'; -import {Dialog} from '@material/mwc-dialog'; - -let element; - -suite('mwc-dialog'); - -beforeEach(() => { - element = document.createElement('mwc-dialog'); - document.body.appendChild(element); -}); - -afterEach(() => { - document.body.removeChild(element); -}); - -test('initializes as an mwc-dialog', () => { - assert.instanceOf(element, Dialog); -}); diff --git a/test/unit/mwc-fab.test.js b/test/unit/mwc-fab.test.ts similarity index 100% rename from test/unit/mwc-fab.test.js rename to test/unit/mwc-fab.test.ts index 358ddd96e..283b81e79 100644 --- a/test/unit/mwc-fab.test.js +++ b/test/unit/mwc-fab.test.ts @@ -73,12 +73,12 @@ test('setting `icon` sets `aria-label` of the button', async () => { test('setting `label` sets `aria-label` of the button, overriding `icon`', async () => { element.icon = 'check'; await element.updateComplete; - button = element.shadowRoot.querySelector('button'); + let button = element.shadowRoot.querySelector('button'); assert.equal(button.getAttribute('aria-label'), 'check'); element.label = 'label text'; await element.updateComplete; - let button = element.shadowRoot.querySelector('button'); + button = element.shadowRoot.querySelector('button'); assert.equal(button.getAttribute('aria-label'), 'label text'); element.label = undefined; diff --git a/test/unit/mwc-formfield.test.js b/test/unit/mwc-formfield.test.ts similarity index 100% rename from test/unit/mwc-formfield.test.js rename to test/unit/mwc-formfield.test.ts diff --git a/test/unit/mwc-icon-button.test.js b/test/unit/mwc-icon-button.test.ts similarity index 90% rename from test/unit/mwc-icon-button.test.js rename to test/unit/mwc-icon-button.test.ts index 0e112f5e3..fe2b138a1 100644 --- a/test/unit/mwc-icon-button.test.js +++ b/test/unit/mwc-icon-button.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {assert} from 'chai'; +import {assert, expect} from 'chai'; import {IconButton} from '@material/mwc-icon-button'; const ICON_SELECTOR = '.mdc-icon-button__icon.mdc-icon-button__icon--on'; @@ -122,7 +122,14 @@ svgTemplate.innerHTML = ` `; test('nodes with `slot=icon` will serve as the on icon', async () => { - const icon = svgTemplate.content.querySelector('svg[slot="icon"]').cloneNode(true); + const iconQuery = svgTemplate.content.querySelector('svg[slot="icon"]'); + expect(iconQuery).to.be.ok; + + if (!iconQuery) { + return; + } + + const icon = iconQuery.cloneNode(true); element.appendChild(icon); await element.updateComplete; const iconSlot = element.shadowRoot.querySelector('slot[name="icon"]'); @@ -130,7 +137,14 @@ test('nodes with `slot=icon` will serve as the on icon', async () => { }); test('nodes with `slot=offIcon` will serve as the off icon', async () => { - const icon = svgTemplate.content.querySelector('svg[slot="offIcon"]').cloneNode(true); + const iconQuery = svgTemplate.content.querySelector('svg[slot="offIcon"]'); + expect(iconQuery).to.be.ok; + + if (!iconQuery) { + return; + } + + const icon = iconQuery.cloneNode(true); element.appendChild(icon); await element.updateComplete; const iconSlot = element.shadowRoot.querySelector('slot[name="offIcon"]'); @@ -138,7 +152,14 @@ test('nodes with `slot=offIcon` will serve as the off icon', async () => { }); test('icon-button does not toggle with only slotted icon', async () => { - const icon = svgTemplate.content.querySelector('svg[slot="icon"]').cloneNode(true); + const iconQuery = svgTemplate.content.querySelector('svg[slot="icon"]'); + expect(iconQuery).to.be.ok; + + if (!iconQuery) { + return; + } + + const icon = iconQuery.cloneNode(true); element.appendChild(icon); await element.updateComplete; assert.equal(element.on, true); diff --git a/test/unit/mwc-icon.test.js b/test/unit/mwc-icon.test.ts similarity index 100% rename from test/unit/mwc-icon.test.js rename to test/unit/mwc-icon.test.ts diff --git a/test/unit/mwc-linear-progress.test.js b/test/unit/mwc-linear-progress.test.ts similarity index 100% rename from test/unit/mwc-linear-progress.test.js rename to test/unit/mwc-linear-progress.test.ts diff --git a/test/unit/mwc-list.test.js b/test/unit/mwc-list.test.js deleted file mode 100644 index 94cf9b97d..000000000 --- a/test/unit/mwc-list.test.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {assert} from 'chai'; -import {ListItem} from '@material/mwc-list/mwc-list-item.js'; -import {ListItemSeparator} from '@material/mwc-list/mwc-list-item-separator.js'; - -let element; - -suite('mwc-list-item'); - -beforeEach(() => { - element = document.createElement('mwc-list-item'); - document.body.appendChild(element); -}); - -afterEach(() => { - document.body.removeChild(element); -}); - -test('initializes as an mwc-list-item', () => { - assert.instanceOf(element, ListItem); -}); - -suite('mwc-list-item-separator'); - -beforeEach(() => { - element = document.createElement('mwc-list-item-separator'); - document.body.appendChild(element); -}); - -afterEach(() => { - document.body.removeChild(element); -}); - -test('initializes as an mwc-list-item-separator', () => { - assert.instanceOf(element, ListItemSeparator); -}); diff --git a/test/unit/mwc-menu.test.js b/test/unit/mwc-menu.test.js deleted file mode 100644 index 1ccfbe144..000000000 --- a/test/unit/mwc-menu.test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {assert} from 'chai'; -import {Menu} from '@material/mwc-menu'; - -let element; - -suite('mwc-menu'); - -beforeEach(() => { - element = document.createElement('mwc-menu'); - document.body.appendChild(element); -}); - -afterEach(() => { - document.body.removeChild(element); -}); - -test('initializes as an mwc-menu', () => { - assert.instanceOf(element, Menu); -}); diff --git a/test/unit/mwc-radio.test.js b/test/unit/mwc-radio.test.ts similarity index 100% rename from test/unit/mwc-radio.test.js rename to test/unit/mwc-radio.test.ts diff --git a/test/unit/mwc-ripple.test.js b/test/unit/mwc-ripple.test.ts similarity index 100% rename from test/unit/mwc-ripple.test.js rename to test/unit/mwc-ripple.test.ts diff --git a/test/unit/mwc-select.test.js b/test/unit/mwc-select.test.ts similarity index 100% rename from test/unit/mwc-select.test.js rename to test/unit/mwc-select.test.ts diff --git a/test/unit/mwc-snackbar.test.js b/test/unit/mwc-snackbar.test.ts similarity index 100% rename from test/unit/mwc-snackbar.test.js rename to test/unit/mwc-snackbar.test.ts diff --git a/test/unit/mwc-switch.test.js b/test/unit/mwc-switch.test.ts similarity index 98% rename from test/unit/mwc-switch.test.js rename to test/unit/mwc-switch.test.ts index 406d46985..108e1461f 100644 --- a/test/unit/mwc-switch.test.js +++ b/test/unit/mwc-switch.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {assert} from 'chai'; +import {assert, expect} from 'chai'; import {fake} from 'sinon'; import {Switch} from '@material/mwc-switch'; diff --git a/test/unit/mwc-tabs.test.js b/test/unit/mwc-tabs.test.ts similarity index 100% rename from test/unit/mwc-tabs.test.js rename to test/unit/mwc-tabs.test.ts diff --git a/test/unit/mwc-textfield.test.js b/test/unit/mwc-textfield.test.ts similarity index 90% rename from test/unit/mwc-textfield.test.js rename to test/unit/mwc-textfield.test.ts index 951aeac00..f80c1faaa 100644 --- a/test/unit/mwc-textfield.test.js +++ b/test/unit/mwc-textfield.test.ts @@ -15,7 +15,7 @@ */ import {assert} from 'chai'; -import {Textfield} from '@material/mwc-textfield'; +import {TextField} from '@material/mwc-textfield'; let element; @@ -31,5 +31,5 @@ afterEach(() => { }); test('initializes as an mwc-textfield', () => { - assert.instanceOf(element, Textfield); + assert.instanceOf(element, TextField); }); diff --git a/test/unit/mwc-typography.test.js b/test/unit/mwc-typography.test.js deleted file mode 100644 index 6de02c71a..000000000 --- a/test/unit/mwc-typography.test.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {assert} from 'chai'; -import {style as typographyStyle} from '@material/mwc-typography'; -import {TemplateResult} from 'lit-html'; - -suite('mwc-typography'); - -test('initializes as an mwc-typography', () => { - assert.instanceOf(typographyStyle, TemplateResult); -});