diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-08-31 08:47:28 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-08-31 08:47:28 +0000 |
commit | 29df3f1d3f2624e84f89610dd48c0b4452255df8 (patch) | |
tree | de36337bf4c81f53be5c8a73edf70076851ad784 | |
parent | 9c491bc628f5a72424b82bb01e2457150bf2e71c (diff) | |
parent | 1e2e0af67d1ca051e4b87c77c832e1d6644eb439 (diff) | |
download | gitlab-ce-29df3f1d3f2624e84f89610dd48c0b4452255df8.tar.gz |
Merge branch 'winh-fix-pdf-page-spec-timing' into 'master'
Remove waiting from PDF page component test
See merge request gitlab-org/gitlab-ce!21365
-rw-r--r-- | spec/javascripts/pdf/page_spec.js | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/spec/javascripts/pdf/page_spec.js b/spec/javascripts/pdf/page_spec.js index ff1bfd7f650..a207f2afce6 100644 --- a/spec/javascripts/pdf/page_spec.js +++ b/spec/javascripts/pdf/page_spec.js @@ -3,53 +3,45 @@ import pdfjsLib from 'vendor/pdf'; import workerSrc from 'vendor/pdf.worker.min'; import PageComponent from '~/pdf/page/index.vue'; -import testPDF from '../fixtures/blob/pdf/test.pdf'; - -const Component = Vue.extend(PageComponent); +import mountComponent from 'spec/helpers/vue_mount_component_helper'; +import testPDF from 'spec/fixtures/blob/pdf/test.pdf'; describe('Page component', () => { + const Component = Vue.extend(PageComponent); let vm; let testPage; - pdfjsLib.PDFJS.workerSrc = workerSrc; - - const checkRendered = (done) => { - if (vm.rendering) { - setTimeout(() => { - checkRendered(done); - }, 100); - } else { - done(); - } - }; - beforeEach((done) => { - pdfjsLib.getDocument(testPDF) + beforeEach(done => { + pdfjsLib.PDFJS.workerSrc = workerSrc; + pdfjsLib + .getDocument(testPDF) .then(pdf => pdf.getPage(1)) - .then((page) => { + .then(page => { testPage = page; - done(); }) - .catch((error) => { - done.fail(error); - }); + .then(done) + .catch(done.fail); }); - describe('render', () => { - beforeEach((done) => { - vm = new Component({ - propsData: { - page: testPage, - number: 1, - }, - }); - - vm.$mount(); + afterEach(() => { + vm.$destroy(); + }); - checkRendered(done); + it('renders the page when mounting', done => { + const promise = Promise.resolve(); + spyOn(testPage, 'render').and.callFake(() => promise); + vm = mountComponent(Component, { + page: testPage, + number: 1, }); + expect(vm.rendering).toBe(true); - it('renders first page', () => { - expect(vm.$el.tagName).toBeDefined(); - }); + promise + .then(() => { + expect(testPage.render).toHaveBeenCalledWith(vm.renderContext); + expect(vm.rendering).toBe(false); + }) + .then(done) + .catch(done.fail); }); }); |