From 6f5723a169b5d400c136dbd844fc54c68e5f8563 Mon Sep 17 00:00:00 2001 From: Johann Hubert Sonntagbauer Date: Tue, 9 Oct 2018 20:03:09 +0200 Subject: enable jasmine/new-line-before-expect --- spec/javascripts/lib/utils/common_utils_spec.js | 13 +++++++++++++ spec/javascripts/lib/utils/dom_utils_spec.js | 2 ++ spec/javascripts/lib/utils/number_utility_spec.js | 4 ++++ spec/javascripts/lib/utils/sticky_spec.js | 1 + spec/javascripts/lib/utils/text_markdown_spec.js | 2 ++ 5 files changed, 22 insertions(+) (limited to 'spec/javascripts/lib') diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index b2b8f64d705..514d6ddeae5 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -42,6 +42,7 @@ describe('common_utils', () => { it('should remove the question mark from the search params', () => { const paramsArray = commonUtils.urlParamsToArray('?test=thing'); + expect(paramsArray[0][0]).not.toBe('?'); }); }); @@ -121,6 +122,7 @@ describe('common_utils', () => { commonUtils.handleLocationHash(); expectGetElementIdToHaveBeenCalledWith('test'); + expect(window.scrollY).toBe(document.getElementById('test').offsetTop); document.getElementById('parent').remove(); @@ -139,6 +141,7 @@ describe('common_utils', () => { expectGetElementIdToHaveBeenCalledWith('test'); expectGetElementIdToHaveBeenCalledWith('user-content-test'); + expect(window.scrollY).toBe(document.getElementById('user-content-test').offsetTop); document.getElementById('parent').remove(); @@ -159,6 +162,7 @@ describe('common_utils', () => { expectGetElementIdToHaveBeenCalledWith('test'); expectGetElementIdToHaveBeenCalledWith('user-content-test'); + expect(window.scrollY).toBe(document.getElementById('user-content-test').offsetTop - 50); expect(window.scrollBy).toHaveBeenCalledWith(0, -50); @@ -222,20 +226,24 @@ describe('common_utils', () => { it('should return valid parameter', () => { const value = commonUtils.getParameterByName('scope'); + expect(commonUtils.getParameterByName('p')).toEqual('2'); expect(value).toBe('all'); }); it('should return invalid parameter', () => { const value = commonUtils.getParameterByName('fakeParameter'); + expect(value).toBe(null); }); it('should return valid paramentes if URL is provided', () => { let value = commonUtils.getParameterByName('foo', 'http://cocteau.twins/?foo=bar'); + expect(value).toBe('bar'); value = commonUtils.getParameterByName('manan', 'http://cocteau.twins/?foo=bar&manan=canchu'); + expect(value).toBe('canchu'); }); }); @@ -395,6 +403,7 @@ describe('common_utils', () => { }) ).catch(done.fail)).then((respBackoff) => { const timeouts = window.setTimeout.calls.allArgs().map(([, timeout]) => timeout); + expect(timeouts).toEqual([2000, 4000]); expect(respBackoff).toBe(expectedResponseValue); done(); @@ -405,6 +414,7 @@ describe('common_utils', () => { commonUtils.backOff(next => next(), 64000) .catch((errBackoffResp) => { const timeouts = window.setTimeout.calls.allArgs().map(([, timeout]) => timeout); + expect(timeouts).toEqual([2000, 4000, 8000, 16000, 32000, 32000]); expect(errBackoffResp instanceof Error).toBe(true); expect(errBackoffResp.message).toBe('BACKOFF_TIMEOUT'); @@ -450,6 +460,7 @@ describe('common_utils', () => { const favicon = document.getElementById('favicon'); favicon.setAttribute('href', 'new/favicon'); commonUtils.resetFavicon(); + expect(document.getElementById('favicon').getAttribute('href')).toEqual('default/favicon'); }); }); @@ -507,6 +518,7 @@ describe('common_utils', () => { commonUtils.setCiStatusFavicon(BUILD_URL) .catch(() => { const favicon = document.getElementById('favicon'); + expect(favicon.getAttribute('href')).toEqual(faviconDataUrl); done(); }); @@ -520,6 +532,7 @@ describe('common_utils', () => { commonUtils.setCiStatusFavicon(BUILD_URL) .then(() => { const favicon = document.getElementById('favicon'); + expect(favicon.getAttribute('href')).toEqual(faviconWithOverlayDataUrl); done(); }) diff --git a/spec/javascripts/lib/utils/dom_utils_spec.js b/spec/javascripts/lib/utils/dom_utils_spec.js index 867bf5912d1..1fb2e4584a0 100644 --- a/spec/javascripts/lib/utils/dom_utils_spec.js +++ b/spec/javascripts/lib/utils/dom_utils_spec.js @@ -18,6 +18,7 @@ describe('DOM Utils', () => { it('adds class if element exists', () => { const childElement = parentElement.querySelector('.child'); + expect(childElement).not.toBe(null); addClassIfElementExists(childElement, className); @@ -27,6 +28,7 @@ describe('DOM Utils', () => { it('does not throw if element does not exist', () => { const childElement = parentElement.querySelector('.other-child'); + expect(childElement).toBe(null); addClassIfElementExists(childElement, className); diff --git a/spec/javascripts/lib/utils/number_utility_spec.js b/spec/javascripts/lib/utils/number_utility_spec.js index fcf27f6805f..a5099a2a3b8 100644 --- a/spec/javascripts/lib/utils/number_utility_spec.js +++ b/spec/javascripts/lib/utils/number_utility_spec.js @@ -10,6 +10,7 @@ describe('Number Utils', () => { const formattedNumber = formatRelevantDigits('1000.1234567'); const rightFromDecimal = formattedNumber.split('.')[1]; const leftFromDecimal = formattedNumber.split('.')[0]; + expect(rightFromDecimal.length).toBe(4); expect(leftFromDecimal.length).toBe(4); }); @@ -18,6 +19,7 @@ describe('Number Utils', () => { const formattedNumber = formatRelevantDigits('0.1234567'); const rightFromDecimal = formattedNumber.split('.')[1]; const leftFromDecimal = formattedNumber.split('.')[0]; + expect(rightFromDecimal.length).toBe(3); expect(leftFromDecimal.length).toBe(1); }); @@ -26,6 +28,7 @@ describe('Number Utils', () => { const formattedNumber = formatRelevantDigits('10.1234567'); const rightFromDecimal = formattedNumber.split('.')[1]; const leftFromDecimal = formattedNumber.split('.')[0]; + expect(rightFromDecimal.length).toBe(2); expect(leftFromDecimal.length).toBe(2); }); @@ -34,6 +37,7 @@ describe('Number Utils', () => { const formattedNumber = formatRelevantDigits('100.1234567'); const rightFromDecimal = formattedNumber.split('.')[1]; const leftFromDecimal = formattedNumber.split('.')[0]; + expect(rightFromDecimal.length).toBe(1); expect(leftFromDecimal.length).toBe(3); }); diff --git a/spec/javascripts/lib/utils/sticky_spec.js b/spec/javascripts/lib/utils/sticky_spec.js index b87c836654d..694bd136aa3 100644 --- a/spec/javascripts/lib/utils/sticky_spec.js +++ b/spec/javascripts/lib/utils/sticky_spec.js @@ -54,6 +54,7 @@ describe('sticky', () => { expect( el.classList.remove, ).toHaveBeenCalledWith('is-stuck'); + expect( el.classList.contains('is-stuck'), ).toBeFalsy(); diff --git a/spec/javascripts/lib/utils/text_markdown_spec.js b/spec/javascripts/lib/utils/text_markdown_spec.js index 043dd018e0c..73807350679 100644 --- a/spec/javascripts/lib/utils/text_markdown_spec.js +++ b/spec/javascripts/lib/utils/text_markdown_spec.js @@ -95,6 +95,7 @@ describe('init markdown', () => { select }); const expectedText = text.replace(selected, `[${selected}](url)`); + expect(textArea.value).toEqual(expectedText); expect(textArea.selectionStart).toEqual(expectedText.indexOf(select)); expect(textArea.selectionEnd).toEqual(expectedText.indexOf(select) + select.length); @@ -114,6 +115,7 @@ describe('init markdown', () => { select }); const expectedText = initialValue.replace(selected, `[${selected}](url)`); + expect(textArea.value).toEqual(expectedText); expect(textArea.selectionStart).toEqual(expectedText.lastIndexOf(select)); expect(textArea.selectionEnd).toEqual(expectedText.lastIndexOf(select) + select.length); -- cgit v1.2.1