diff options
Diffstat (limited to 'spec/frontend/issue_show/issue_spec.js')
-rw-r--r-- | spec/frontend/issue_show/issue_spec.js | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/spec/frontend/issue_show/issue_spec.js b/spec/frontend/issue_show/issue_spec.js index 29b4f49f74f..befb670c6cd 100644 --- a/spec/frontend/issue_show/issue_spec.js +++ b/spec/frontend/issue_show/issue_spec.js @@ -1,25 +1,44 @@ +import MockAdapter from 'axios-mock-adapter'; +import { useMockIntersectionObserver } from 'helpers/mock_dom_observer'; +import waitForPromises from 'helpers/wait_for_promises'; +import axios from '~/lib/utils/axios_utils'; import initIssuableApp from '~/issue_show/issue'; -import { parseIssuableData } from '~/issue_show/utils/parse_data'; +import * as parseData from '~/issue_show/utils/parse_data'; +import { appProps } from './mock_data'; + +const mock = new MockAdapter(axios); +mock.onGet().reply(200); + +useMockIntersectionObserver(); + +jest.mock('~/lib/utils/poll'); + +const setupHTML = initialData => { + document.body.innerHTML = ` + <div id="js-issuable-app"></div> + <script id="js-issuable-app-initial-data" type="application/json"> + ${JSON.stringify(initialData)} + </script> + `; +}; describe('Issue show index', () => { describe('initIssueableApp', () => { - // Warning: this test is currently faulty. - // More details at https://gitlab.com/gitlab-org/gitlab/-/issues/241717 - // eslint-disable-next-line jest/no-disabled-tests - it.skip('should initialize app with no potential XSS attack', () => { - const d = document.createElement('div'); - d.id = 'js-issuable-app-initial-data'; - - d.innerHTML = JSON.stringify({ - initialDescriptionHtml: '<img src=x onerror=alert(1)>', - }); + it('should initialize app with no potential XSS attack', async () => { + const alertSpy = jest.spyOn(window, 'alert').mockImplementation(() => {}); + const parseDataSpy = jest.spyOn(parseData, 'parseIssuableData'); - document.body.appendChild(d); + setupHTML({ + ...appProps, + initialDescriptionHtml: '<svg onload=window.alert(1)>', + }); - const alertSpy = jest.spyOn(window, 'alert'); - const issuableData = parseIssuableData(); + const issuableData = parseData.parseIssuableData(); initIssuableApp(issuableData); + await waitForPromises(); + + expect(parseDataSpy).toHaveBeenCalled(); expect(alertSpy).not.toHaveBeenCalled(); }); }); |