Skip to content

Commit

Permalink
feat(test): add a unit test to be sure it works with <a> tags as trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Oct 26, 2018
1 parent 0be6fb1 commit 01bb8b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WinEvent, closest } from './polyfill'
const MILLISECONDS_MULTIPLIER = 1000
const Selectors = {
STEPS: '.step',
TRIGGER: '.step-trigger, button, a',
TRIGGER: '.step-trigger, a',
STEPPER: '.bs-stepper'
}

Expand Down
27 changes: 27 additions & 0 deletions tests/units/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ describe('Stepper', function () {
expect(stepper._currentIndex).toEqual(1)
})

it('should go to the next step when user click on a <a> tags which is a trigger', function () {
fixture.innerHTML = [
'<div id="myStepper" class="bs-stepper">',
' <div class="step" data-target="#test1">',
' <a>1</a>',
' </div>',
' <div class="step" data-target="#test2">',
' <a id="trigger2">2</a>',
' </div>',
' <div id="test1">1</div>',
' <div id="test2">2</div>',
'</div>'
].join('')

var stepperNode = document.getElementById('myStepper')
var stepper = new Stepper(stepperNode, {
linear: false
})

var trigger2 = document.querySelector('#trigger2')
trigger2.click()

expect(document.querySelector('#test1').classList.contains('active')).toBe(false)
expect(document.querySelector('#test2').classList.contains('active')).toBe(true)
expect(stepper._currentIndex).toEqual(1)
})

it('should call preventDefault when user click on a step for linear stepper', function () {
fixture.innerHTML = [
'<div id="myStepper" class="bs-stepper">',
Expand Down

0 comments on commit 01bb8b8

Please sign in to comment.