From c8e9df1c607a8a45de07b380acdc28340d8e8fd5 Mon Sep 17 00:00:00 2001 From: GeoSot <geo.sotis@gmail.com> Date: Mon, 29 Nov 2021 12:25:17 +0200 Subject: [PATCH 1/2] Add some tests for alert.js --- js/tests/unit/alert.spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/js/tests/unit/alert.spec.js b/js/tests/unit/alert.spec.js index cdda997c90..f687740192 100644 --- a/js/tests/unit/alert.spec.js +++ b/js/tests/unit/alert.spec.js @@ -179,6 +179,34 @@ describe('Alert', () => { expect(Alert.getInstance(alertEl)).not.toBeNull() expect(fixtureEl.querySelector('.alert')).not.toBeNull() }) + + it('should throw error on undefined method', () => { + fixtureEl.innerHTML = '<div></div>' + + const div = fixtureEl.querySelector('div') + const action = 'undefinedMethod' + + jQueryMock.fn.alert = Alert.jQueryInterface + jQueryMock.elements = [div] + + expect(() => { + jQueryMock.fn.alert.call(jQueryMock, action) + }).toThrowError(TypeError, `No method named "${action}"`) + }) + + it('should throw error on protected method', () => { + fixtureEl.innerHTML = '<div></div>' + + const div = fixtureEl.querySelector('div') + const action = '_getConfig' + + jQueryMock.fn.alert = Alert.jQueryInterface + jQueryMock.elements = [div] + + expect(() => { + jQueryMock.fn.alert.call(jQueryMock, action) + }).toThrowError(TypeError, `No method named "${action}"`) + }) }) describe('getInstance', () => { -- GitLab From 0c5e9ad73402154de263d1f68d649c431153e223 Mon Sep 17 00:00:00 2001 From: XhmikosR <xhmikosr@gmail.com> Date: Mon, 29 Nov 2021 14:28:28 +0200 Subject: [PATCH 2/2] Update alert.spec.js --- js/tests/unit/alert.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/tests/unit/alert.spec.js b/js/tests/unit/alert.spec.js index f687740192..eb3d3e5fa3 100644 --- a/js/tests/unit/alert.spec.js +++ b/js/tests/unit/alert.spec.js @@ -180,7 +180,7 @@ describe('Alert', () => { expect(fixtureEl.querySelector('.alert')).not.toBeNull() }) - it('should throw error on undefined method', () => { + it('should throw an error on undefined method', () => { fixtureEl.innerHTML = '<div></div>' const div = fixtureEl.querySelector('div') @@ -194,7 +194,7 @@ describe('Alert', () => { }).toThrowError(TypeError, `No method named "${action}"`) }) - it('should throw error on protected method', () => { + it('should throw an error on protected method', () => { fixtureEl.innerHTML = '<div></div>' const div = fixtureEl.querySelector('div') -- GitLab