Sha256: 8437575e9de792b0b9b432ed2e01d0cf5c71c73e4fc3f60731bdc2b909b4bc00

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

/* global describe it expect beforeEach afterEach */

var $ = window.jQuery

describe('shim-links-with-button-role', function () {
  'use strict'
  var GOVUK = window.GOVUK

  var $buttonLink
  var keyupEvent

  beforeEach(function () {
    $buttonLink = $('<a role="button">Button</a>')
    $buttonLink.on('click', function () {
      $buttonLink.addClass('clicked')
    })
    $(document.body).append($buttonLink)
    keyupEvent = $.Event('keyup')
    keyupEvent.target = $buttonLink.get(0)
    GOVUK.shimLinksWithButtonRole.init()
  })

  afterEach(function () {
    $buttonLink.remove()
    $(document).off('keyup')
  })

  it('should trigger event on space', function () {
    // Ideally we’d test the page loading functionality but that seems hard to
    // do within a Jasmine context. Settle for checking a bound event trigger.
    keyupEvent.which = 32 // Space character
    $(document).trigger(keyupEvent)
    expect($buttonLink.hasClass('clicked')).toBe(true)
  })

  it('should not trigger event on tab', function () {
    keyupEvent.which = 9 // Tab character
    $(document).trigger(keyupEvent)
    expect($buttonLink.hasClass('clicked')).toBe(false)
  })
})

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-5.0.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-4.18.4 app/assets/spec/unit/shim-links-with-button-role.spec.js