Skip to content

Commit

Permalink
CTSKF-445 Fix Modules.OffenceSearchInput_spec.js
Browse files Browse the repository at this point in the history
* Moves `$('body .mod-search-input').remove()` to an afterEach function,
instead of calling it as the first step of the beforeEach function. This
previous approach meant that the last test in this file was not torn
down correctly and caused subsequent tests to fail.

* Fixes the test defined in `describe('...trackUserInput'...` which
fails because `module.$input.val('mudr')` is called before module has
been initialised. This is done by calling `module.init()` before
`module.$input.val('mudr')`.
  • Loading branch information
mpw5 committed Dec 1, 2023
1 parent 9bd0cea commit cfbeb6d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spec/javascripts/Modules.OffenceSearchInput_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ describe('Modules.OffenceSearchInput.js', function () {
}

beforeEach(function () {
$('body .mod-search-input').remove()
$('body').append(view())
})

afterEach(function () {
$('body .mod-search-input').remove()
})

describe('...defaults', function () {
it('`this.el`', function () {
expect(module.el).toEqual('.mod-search-input')
Expand Down Expand Up @@ -176,10 +179,11 @@ describe('Modules.OffenceSearchInput.js', function () {
describe('...trackUserInput', function () {
it('should use `moj.Modules.Debounce`', function () {
spyOn(moj.Modules.Debounce, 'init')
module.$input.val('mudr')

module.init()

module.$input.val('mudr')

// trigger keyup
module.$input.trigger($.Event('keyup', {
keyCode: 65
Expand Down

0 comments on commit cfbeb6d

Please sign in to comment.