Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion test/dasherize.ts
Original file line number Diff line number Diff line change
@@ -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]> = [
Expand All @@ -16,3 +16,37 @@ 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', () => {
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', () => {
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')
})
})