|
12 | 12 | import '@spectrum-web-components/status-light/sp-status-light.js'; |
13 | 13 | import { StatusLight } from '@spectrum-web-components/status-light'; |
14 | 14 | import { elementUpdated, expect, fixture, html } from '@open-wc/testing'; |
| 15 | +import { spy } from 'sinon'; |
15 | 16 |
|
16 | 17 | describe('Status Light', () => { |
17 | 18 | it('loads correctly', async () => { |
@@ -41,4 +42,41 @@ describe('Status Light', () => { |
41 | 42 | expect(el.hasAttribute('aria-disabled')).to.be.true; |
42 | 43 | expect(el.getAttribute('aria-disabled')).to.equal('true'); |
43 | 44 | }); |
| 45 | + |
| 46 | + describe('dev mode warnings', () => { |
| 47 | + let warningMessage: typeof window.__swc.warn; |
| 48 | + |
| 49 | + beforeEach(() => { |
| 50 | + // Create __swc if it doesn't exist |
| 51 | + window.__swc = window.__swc || { warn: () => {} }; |
| 52 | + // Store original warn function |
| 53 | + warningMessage = window.__swc.warn; |
| 54 | + // Reset issued warnings to avoid dedupe interference |
| 55 | + window.__swc.issuedWarnings = new Set(); |
| 56 | + // Enable debug guard |
| 57 | + window.__swc.DEBUG = true; |
| 58 | + }); |
| 59 | + |
| 60 | + afterEach(() => { |
| 61 | + // Restore original warn function |
| 62 | + window.__swc.warn = warningMessage; |
| 63 | + }); |
| 64 | + |
| 65 | + it('warns when unsupported variant is used (brown)', async () => { |
| 66 | + const warnSpy = spy(); |
| 67 | + window.__swc.warn = warnSpy as unknown as typeof window.__swc.warn; |
| 68 | + |
| 69 | + const el = await fixture<StatusLight>(html` |
| 70 | + <sp-status-light variant="brown"></sp-status-light> |
| 71 | + `); |
| 72 | + |
| 73 | + await elementUpdated(el); |
| 74 | + |
| 75 | + expect(warnSpy.called).to.be.true; |
| 76 | + expect(warnSpy.firstCall.args[0]).to.equal(el); |
| 77 | + expect(warnSpy.firstCall.args[1]).to.equal( |
| 78 | + `<${el.localName}> element expects the "variant" attribute to be one of the following:` |
| 79 | + ); |
| 80 | + }); |
| 81 | + }); |
44 | 82 | }); |
0 commit comments