From e8f08d1802976b8200551de49354757f84e438cf Mon Sep 17 00:00:00 2001 From: Nikon the Third Date: Fri, 19 Feb 2021 09:24:53 +0100 Subject: Adjust regex `SAFE_URL_PATTERN` for use with test method of regexes. (#33136) The test method on regexes behaves different than the match method on strings in the presence of the global modifier. Add a unit test for sanitizing the same template twice. Co-authored-by: XhmikosR --- js/tests/unit/util/sanitizer.spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/util/sanitizer.spec.js b/js/tests/unit/util/sanitizer.spec.js index 869b8c561..7379d221f 100644 --- a/js/tests/unit/util/sanitizer.spec.js +++ b/js/tests/unit/util/sanitizer.spec.js @@ -66,5 +66,15 @@ describe('Sanitizer', () => { expect(result).toEqual(template) expect(DOMParser.prototype.parseFromString).not.toHaveBeenCalled() }) + + it('should allow multiple sanitation passes of the same template', () => { + const template = '' + + const firstResult = sanitizeHtml(template, DefaultAllowlist, null) + const secondResult = sanitizeHtml(template, DefaultAllowlist, null) + + expect(firstResult).toContain('src') + expect(secondResult).toContain('src') + }) }) }) -- cgit v1.2.3 From 5693f1ad863832adb01ed1ca9cd24c825fc640f4 Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Sun, 21 Feb 2021 06:00:03 +0000 Subject: Fix small typos / follow-up to #32630 (#33164) --- js/tests/unit/tab.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tab.spec.js b/js/tests/unit/tab.spec.js index 463fb79af..c52812f52 100644 --- a/js/tests/unit/tab.spec.js +++ b/js/tests/unit/tab.spec.js @@ -160,7 +160,7 @@ describe('Tab', () => { fixtureEl.innerHTML = [ '', '
', '
', -- cgit v1.2.3 From dc5e3328c12058de7fb6404edbe5dcee61f3400f Mon Sep 17 00:00:00 2001 From: Rohit Sharma Date: Mon, 22 Feb 2021 12:31:04 +0530 Subject: Allow constructors to accept a CSS selector (#32245) Co-authored-by: XhmikosR Co-authored-by: Mark Otto --- js/tests/unit/alert.spec.js | 11 +++++++++++ js/tests/unit/button.spec.js | 10 ++++++++++ js/tests/unit/carousel.spec.js | 11 +++++++++++ js/tests/unit/collapse.spec.js | 11 +++++++++++ js/tests/unit/dropdown.spec.js | 18 ++++++++++++++++++ js/tests/unit/modal.spec.js | 13 +++++++++++++ js/tests/unit/scrollspy.spec.js | 11 +++++++++++ js/tests/unit/tab.spec.js | 16 ++++++++++++++++ js/tests/unit/toast.spec.js | 11 +++++++++++ js/tests/unit/tooltip.spec.js | 11 +++++++++++ 10 files changed, 123 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/alert.spec.js b/js/tests/unit/alert.spec.js index 916c7fd07..194da420e 100644 --- a/js/tests/unit/alert.spec.js +++ b/js/tests/unit/alert.spec.js @@ -15,6 +15,17 @@ describe('Alert', () => { clearFixture() }) + it('should take care of element either passed as a CSS selector or DOM element', () => { + fixtureEl.innerHTML = '
' + + const alertEl = fixtureEl.querySelector('.alert') + const alertBySelector = new Alert('.alert') + const alertByElement = new Alert(alertEl) + + expect(alertBySelector._element).toEqual(alertEl) + expect(alertByElement._element).toEqual(alertEl) + }) + it('should return version', () => { expect(typeof Alert.VERSION).toEqual('string') }) diff --git a/js/tests/unit/button.spec.js b/js/tests/unit/button.spec.js index e442fd90d..e7d92cb6d 100644 --- a/js/tests/unit/button.spec.js +++ b/js/tests/unit/button.spec.js @@ -18,6 +18,16 @@ describe('Button', () => { clearFixture() }) + it('should take care of element either passed as a CSS selector or DOM element', () => { + fixtureEl.innerHTML = '' + const buttonEl = fixtureEl.querySelector('[data-bs-toggle="button"]') + const buttonBySelector = new Button('[data-bs-toggle="button"]') + const buttonByElement = new Button(buttonEl) + + expect(buttonBySelector._element).toEqual(buttonEl) + expect(buttonByElement._element).toEqual(buttonEl) + }) + describe('VERSION', () => { it('should return plugin version', () => { expect(Button.VERSION).toEqual(jasmine.any(String)) diff --git a/js/tests/unit/carousel.spec.js b/js/tests/unit/carousel.spec.js index 533e1ba7e..c475489c0 100644 --- a/js/tests/unit/carousel.spec.js +++ b/js/tests/unit/carousel.spec.js @@ -52,6 +52,17 @@ describe('Carousel', () => { }) describe('constructor', () => { + it('should take care of element either passed as a CSS selector or DOM element', () => { + fixtureEl.innerHTML = '' + + const carouselEl = fixtureEl.querySelector('#myCarousel') + const carouselBySelector = new Carousel('#myCarousel') + const carouselByElement = new Carousel(carouselEl) + + expect(carouselBySelector._element).toEqual(carouselEl) + expect(carouselByElement._element).toEqual(carouselEl) + }) + it('should go to next item if right arrow key is pressed', done => { fixtureEl.innerHTML = [ '