Sha256: a66823ec42915aafe3eea512cd57ca3be2b13f8c095b3517dde3a3565d5ff320

Contents?: true

Size: 1.15 KB

Versions: 26

Compression:

Stored size: 1.15 KB

Contents

import { describe, it, expect } from 'vitest'
import { htmlAttributes } from './html-attributes'

describe('htmlAttributes', () => {
  it("returns empty string if no params", () => {
    expect(htmlAttributes({})).toBe("")
  })

  it("returns attributes and data attributes", () => {
    expect(htmlAttributes({ id: "1", "data-foo": "bar" })).toBe(`id='1' data-foo='bar'`)
  })

  it('returns attributes and data attributes with custom data attributes', () => {
    expect(htmlAttributes({ id: '1', data: { foo: 'bar' } })).toBe(`id='1' data-foo='bar'`)
    expect(htmlAttributes({ id: '1', data: { foo: 'bar', baz: 'qux' } })).toBe(`id='1' data-foo='bar' data-baz='qux'`)
    expect(htmlAttributes({ id: '1', data: { foo: { baz: 'qux', quux: 'corge' } } })).toBe(`id='1' data-foo-baz='qux' data-foo-quux='corge'`)
  })

  it('returns disabled if disabled is false', () => {
    expect(htmlAttributes({ disabled: false })).toBe("")
    expect(htmlAttributes({ disabled: true })).toBe("disabled")
  })

  it('escapes html', () => {
    expect(htmlAttributes({ content: "<script>alert('xss')</script>" })).toBe(`content='&lt;script&gt;alert(&#039;xss&#039;)&lt;/script&gt;'`)
  })
})

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.25 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.24 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.23 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.22 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.21 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.20 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.19 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.18 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.17 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.16 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.15 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.14 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.13 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.12 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.11 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.10 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.9 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.8 lib/clapton/javascripts/src/html/html-attributes.spec.ts
clapton-0.0.7 lib/clapton/javascripts/src/html/html-attributes.spec.ts