diff options
author | sstern <sstern@gitlab.com> | 2019-08-30 09:47:03 -0700 |
---|---|---|
committer | sstern <sstern@gitlab.com> | 2019-09-04 15:51:38 -0700 |
commit | 6dc70e9eaab9432d6ad42a5400dd926274f22aae (patch) | |
tree | 32c8c4394d591c3158c12eeb2950966990b129cf | |
parent | 82fb9bda4433b2e4c8a73ae2a62403d4f1867b4d (diff) | |
download | gitlab-ce-6dc70e9eaab9432d6ad42a5400dd926274f22aae.tar.gz |
Restructure tests to clean up mocks in store_spec.js
-rw-r--r-- | spec/frontend/issue_show/store_spec.js | 35 | ||||
-rw-r--r-- | spec/frontend/issue_show/utils/update_description_spec.js | 24 |
2 files changed, 28 insertions, 31 deletions
diff --git a/spec/frontend/issue_show/store_spec.js b/spec/frontend/issue_show/store_spec.js index 1babbcc553e..b7fd70bf00e 100644 --- a/spec/frontend/issue_show/store_spec.js +++ b/spec/frontend/issue_show/store_spec.js @@ -1,5 +1,7 @@ import Store from '~/issue_show/stores'; -import * as updateDescription from '~/issue_show/utils/update_description'; +import updateDescription from '~/issue_show/utils/update_description'; + +jest.mock('~/issue_show/utils/update_description'); describe('Store', () => { let store; @@ -29,38 +31,9 @@ describe('Store', () => { }); it('calls updateDetailsState', () => { - /* - * need to mock 'default' because we need to test its functionality in the next test - * so we spy on its default export and then reset the module. - */ - const spy = jest.spyOn(updateDescription, 'default'); - store.updateState({ description: '' }); - expect(updateDescription.default).toHaveBeenCalledTimes(1); - - spy.mockRestore(); - }); - - it('returns the correct value to be set as descriptionHtml', () => { - store.updateState({ - description: - '<details><summary>One</summary></details><details><summary>Two</summary></details>', - }); - - expect(store.state.descriptionHtml).toEqual( - '<details open="true"><summary>One</summary></details><details><summary>Two</summary></details>', - ); - }); - - describe('when description details returned from api is different then whats currently on the dom', () => { - it('returns the description from the api', () => { - const dataDescription = '<details><summary>One</summary></details>'; - - store.updateState({ description: dataDescription }); - - expect(store.state.descriptionHtml).toEqual(dataDescription); - }); + expect(updateDescription).toHaveBeenCalledTimes(1); }); }); }); diff --git a/spec/frontend/issue_show/utils/update_description_spec.js b/spec/frontend/issue_show/utils/update_description_spec.js new file mode 100644 index 00000000000..b2c6bd3c302 --- /dev/null +++ b/spec/frontend/issue_show/utils/update_description_spec.js @@ -0,0 +1,24 @@ +import updateDescription from '~/issue_show/utils/update_description'; + +describe('updateDescription', () => { + it('returns the correct value to be set as descriptionHtml', () => { + const actual = updateDescription( + '<details><summary>One</summary></details><details><summary>Two</summary></details>', + [{ open: true }, { open: false }], // mocking NodeList from the dom. + ); + + expect(actual).toEqual( + '<details open="true"><summary>One</summary></details><details><summary>Two</summary></details>', + ); + }); + + describe('when description details returned from api is different then whats currently on the dom', () => { + it('returns the description from the api', () => { + const dataDescription = '<details><summary>One</summary></details>'; + + const actual = updateDescription(dataDescription, []); + + expect(actual).toEqual(dataDescription); + }); + }); +}); |