diff --git a/package.json b/package.json index be991f89a..71c11b281 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "node": "10.15.3" }, "scripts": { - "test": "gulp lint", + "test": "gulp lint && jest tests/javascripts", "build": "gulp", "watch": "gulp watch" }, @@ -43,6 +43,7 @@ "gulp-jshint": "2.1.0", "gulp-prettyerror": "1.2.1", "gulp-sass-lint": "1.4.0", + "jest": "24.7.1", "jshint": "2.10.2", "jshint-stylish": "2.2.1" } diff --git a/tests/javascripts/autofocus.test.js b/tests/javascripts/autofocus.test.js new file mode 100644 index 000000000..8419b2d62 --- /dev/null +++ b/tests/javascripts/autofocus.test.js @@ -0,0 +1,84 @@ +beforeAll(() => { + // set up jQuery + window.jQuery = require('jquery'); + $ = window.jQuery; + + // load module code + require('govuk_frontend_toolkit/javascripts/govuk/modules.js'); + require('../../app/assets/javascripts/autofocus.js'); +}); + +afterAll(() => { + window.jQuery = null; + $ = null; + + delete window.GOVUK; +}); + +describe('Autofocus', () => { + + let focusHandler; + let search; + + beforeEach(() => { + + // set up DOM + document.body.innerHTML = + `