import { mount } from '@vue/test-utils' import Vue from 'vue' import Anchor from '..' const { Link } = Anchor describe('Anchor Render', () => { it('Anchor render perfectly', (done) => { const wrapper = mount({ render () { return ( ) }, }, { sync: false }) Vue.nextTick(() => { wrapper.find('a[href="#API"]').trigger('click') wrapper.vm.$refs.anchor.handleScroll() setTimeout(() => { expect(wrapper.vm.$refs.anchor.$data.activeLink).not.toBe(null) done() }, 1000) }) }) it('Anchor render perfectly for complete href - click', (done) => { const wrapper = mount({ render () { return ( ) }, }, { sync: false }) Vue.nextTick(() => { wrapper.find('a[href="http://www.example.com/#API"]').trigger('click') expect(wrapper.vm.$refs.anchor.$data.activeLink).toBe('http://www.example.com/#API') done() }) }) it('Anchor render perfectly for complete href - scoll', (done) => { const wrapper = mount({ render () { return (
Hello
) }, }, { sync: false, attachToDocument: true }) Vue.nextTick(() => { wrapper.vm.$refs.anchor.handleScroll() expect(wrapper.vm.$refs.anchor.$data.activeLink).toBe('http://www.example.com/#API') done() }) }) it('Anchor render perfectly for complete href - scollTo', (done) => { const wrapper = mount({ render () { return (
Hello
) }, }, { sync: false, attachToDocument: true }) Vue.nextTick(() => { wrapper.vm.$refs.anchor.handleScrollTo('##API') expect(wrapper.vm.$refs.anchor.$data.activeLink).toBe('##API') done() }) }) })