Commit 29df3f1d authored by Filipa Lacerda's avatar Filipa Lacerda

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
parents 9c491bc6 1e2e0af6
...@@ -3,53 +3,45 @@ import pdfjsLib from 'vendor/pdf'; ...@@ -3,53 +3,45 @@ import pdfjsLib from 'vendor/pdf';
import workerSrc from 'vendor/pdf.worker.min'; import workerSrc from 'vendor/pdf.worker.min';
import PageComponent from '~/pdf/page/index.vue'; import PageComponent from '~/pdf/page/index.vue';
import testPDF from '../fixtures/blob/pdf/test.pdf'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
import testPDF from 'spec/fixtures/blob/pdf/test.pdf';
const Component = Vue.extend(PageComponent);
describe('Page component', () => { describe('Page component', () => {
const Component = Vue.extend(PageComponent);
let vm; let vm;
let testPage; let testPage;
pdfjsLib.PDFJS.workerSrc = workerSrc;
const checkRendered = (done) => {
if (vm.rendering) {
setTimeout(() => {
checkRendered(done);
}, 100);
} else {
done();
}
};
beforeEach((done) => { beforeEach(done => {
pdfjsLib.getDocument(testPDF) pdfjsLib.PDFJS.workerSrc = workerSrc;
pdfjsLib
.getDocument(testPDF)
.then(pdf => pdf.getPage(1)) .then(pdf => pdf.getPage(1))
.then((page) => { .then(page => {
testPage = page; testPage = page;
done();
}) })
.catch((error) => { .then(done)
done.fail(error); .catch(done.fail);
}); });
afterEach(() => {
vm.$destroy();
}); });
describe('render', () => { it('renders the page when mounting', done => {
beforeEach((done) => { const promise = Promise.resolve();
vm = new Component({ spyOn(testPage, 'render').and.callFake(() => promise);
propsData: { vm = mountComponent(Component, {
page: testPage, page: testPage,
number: 1, number: 1,
},
}); });
expect(vm.rendering).toBe(true);
vm.$mount(); promise
.then(() => {
checkRendered(done); expect(testPage.render).toHaveBeenCalledWith(vm.renderContext);
}); expect(vm.rendering).toBe(false);
})
it('renders first page', () => { .then(done)
expect(vm.$el.tagName).toBeDefined(); .catch(done.fail);
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment