-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: find a new way to validate defineElement warnings without throw…
…ing off coverage
- Loading branch information
1 parent
7b4b5ac
commit 4a164cf
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you 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 REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { expect } from '@open-wc/testing'; | ||
import { stub } from 'sinon'; | ||
|
||
// for window.__swc | ||
import '@spectrum-web-components/base'; | ||
|
||
const elements = [ | ||
{ | ||
name: 'sp-color-area', | ||
register: () => | ||
import('@spectrum-web-components/color-area/sp-color-area.js'), | ||
}, | ||
]; | ||
|
||
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); | ||
|
||
describe('define-element', function () { | ||
this.retries(0); | ||
beforeEach(function () { | ||
window.__swc.verbose = true; | ||
this.warn = stub(console, 'warn'); | ||
}); | ||
afterEach(function () { | ||
this.warn.resetHistory(); | ||
window.__swc.verbose = false; | ||
this.warn.restore(); | ||
}); | ||
elements.map(({ name, register }) => | ||
it('warns on redefinition', async function () { | ||
const error = isSafari ? 'same tag name' : 'has already been'; | ||
let caughtError: Error | undefined; | ||
|
||
customElements.define(name, class extends HTMLElement {}); | ||
try { | ||
await register(); | ||
} catch (error) { | ||
caughtError = error as Error; | ||
} | ||
|
||
expect(caughtError?.message ?? '').to.include(error); | ||
expect(this.warn.called, 'should call console.warn()').to.be.true; | ||
const spyCall = this.warn.getCall(0); | ||
expect( | ||
(spyCall.args.at(0) as string).includes('redefine'), | ||
'message should warn about redefining an element' | ||
).to.be.true; | ||
}) | ||
); | ||
}); |