feat(ImagePreview): add scale event (#5658)

This commit is contained in:
landluck
2020-02-14 17:21:13 +08:00
committed by GitHub
parent f507b99cb7
commit 9ff8e5635c
5 changed files with 49 additions and 3 deletions
+19
View File
@@ -163,6 +163,25 @@ test('onChange option', async done => {
triggerDrag(swipe, 1000, 0);
});
test('onScale option', async done => {
const { getBoundingClientRect } = Element.prototype;
Element.prototype.getBoundingClientRect = jest.fn(() => ({ width: 100 }));
const instance = ImagePreview({
images,
startPosition: 0,
onScale({ index, scale }) {
expect(index).toEqual(2);
expect(scale <= 2).toBeTruthy();
done();
},
});
const image = instance.$el.getElementsByTagName('img')[0];
triggerZoom(image, 300, 300);
Element.prototype.getBoundingClientRect = getBoundingClientRect;
});
test('register component', () => {
Vue.use(ImagePreview);
expect(Vue.component(ImagePreviewVue.name)).toBeTruthy();