From 34b4e81ebe79b2507b534e2d50ded9f809963008 Mon Sep 17 00:00:00 2001 From: Ultroncn <82553854+Ultroncn@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:59:38 +0000 Subject: [PATCH 1/2] test(dasherize): cover mustDasherize success and error paths mustDasherize is the guard behind @attr and @controller name validation, but it had no tests of its own. Add coverage for the happy path (returns the dasherized name), the custom type argument, and the SyntaxError thrown when the dasherized name contains no dash, including the error message naming the type. --- test/dasherize.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/dasherize.ts b/test/dasherize.ts index 0fbf0fb1..787c8e46 100644 --- a/test/dasherize.ts +++ b/test/dasherize.ts @@ -1,5 +1,5 @@ import {expect} from '@open-wc/testing' -import {dasherize} from '../src/dasherize.js' +import {dasherize, mustDasherize} from '../src/dasherize.js' describe('dasherize', () => { const tests: Array<[PropertyKey, string]> = [ @@ -16,3 +16,24 @@ describe('dasherize', () => { it(`transforms ${String(input)} to ${output}`, () => expect(dasherize(input)).to.equal(output)) ) }) + +describe('mustDasherize', () => { + it('returns the dasherized name when it contains a dash', () => { + expect(mustDasherize('fooBar')).to.equal('foo-bar') + }) + + it('passes the custom type through to the returned name', () => { + expect(mustDasherize('fooBar', 'controller')).to.equal('foo-bar') + }) + + it('throws a SyntaxError when the name has no dash', () => { + expect(() => mustDasherize('json')).to.throw(DOMException, 'property: json is not a valid property name') + }) + + it('names the custom type in the thrown error', () => { + expect(() => mustDasherize('json', 'controller')).to.throw( + DOMException, + 'controller: json is not a valid controller name' + ) + }) +}) From 303fa2354b7b94c66db2213e430945e4b04fc02c Mon Sep 17 00:00:00 2001 From: Ultroncn <82553854+Ultroncn@users.noreply.github.com> Date: Tue, 17 Nov 2026 04:23:52 +0000 Subject: [PATCH 2/2] test(dasherize): assert the thrown DOMException name is SyntaxError Chai's to.throw(DOMException, message) only verifies the constructor and message, so a DOMException created with its default name would still pass. Capture the thrown error and assert its name is SyntaxError as well, keeping the instanceof and message checks. --- test/dasherize.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/dasherize.ts b/test/dasherize.ts index 787c8e46..c3cacf78 100644 --- a/test/dasherize.ts +++ b/test/dasherize.ts @@ -27,13 +27,26 @@ describe('mustDasherize', () => { }) it('throws a SyntaxError when the name has no dash', () => { - expect(() => mustDasherize('json')).to.throw(DOMException, 'property: json is not a valid property name') + let error: unknown + try { + mustDasherize('json') + } catch (caught) { + error = caught + } + expect(error).to.be.instanceOf(DOMException) + expect((error as DOMException).name).to.equal('SyntaxError') + expect((error as DOMException).message).to.equal('property: json is not a valid property name') }) it('names the custom type in the thrown error', () => { - expect(() => mustDasherize('json', 'controller')).to.throw( - DOMException, - 'controller: json is not a valid controller name' - ) + let error: unknown + try { + mustDasherize('json', 'controller') + } catch (caught) { + error = caught + } + expect(error).to.be.instanceOf(DOMException) + expect((error as DOMException).name).to.equal('SyntaxError') + expect((error as DOMException).message).to.equal('controller: json is not a valid controller name') }) })