Closed BTCLTC closed 6 years ago
What should I do?I use Vue but not localVue,it's can work。
@eddyerburgh I use Vue but not localVue,have error: TypeError: Cannot read property '_location' of null at Window.get location [as location] (/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js:187:79)
My code contains: window.location.href
This is a bug caused by setting watchers to sync. I'm looking into a fix, one solution is a change to Vue core—https://github.com/vuejs/vue/issues/8200
The temporary solution is to use Vue.nextTick and set sync
to false to make sure Vue is behaving correctly with updates:
test('use Vue.nextTick', (done) => {
const wrapper = mount(TestComponent, { sync: false })
wrapper.trigger('click')
Vue.nextTick(() => {
expect(wrapper.text()).toBe('updated')
done()
})
})
@eddyerburgh Thank you. It's done.
Had the same issue when specified Component.ts file instead of Component.vue file. Component.ts is the script used in Component.vue script section via <scipt src="./Component.ts">
Although you had the same error, I believe this is a different issue @Alendorff .
Could you open a new issue with a minimal reproduction that I can debug?
@eddyerburgh it works fine with correct import, so I don't think it's really necessary.
@eddyerburgh This is still a problem with latest vue 2.5.22, workaround is still required. Is this normal ?
@Overdrivr Could you open a new issue with a minimal reproduction that I can debug?
I'm swamped with work as of now, but I'll try ;)
Version
1.0.0-beta.16
Reproduction link
https://github.com/yunweb/vue-jest-iview
Steps to reproduce
I was reporting an error when testing my project with Jest. After various investigations, I found that the problem was caused by the use of vue-i18n. When I had each internationalization file (en-US.js, zh-CN When .js, zh-TW.js, vi-VN.js, etc.) exceed 500 lines, it will appear RangeError: Maximum call stack size exceeded at Array.forEach () at orderDeps (nodemodules/@vue_test-utils@1.0.0-beta.16@/dist/vue-test-utils.js:3006:16)
What is expected?
PASS
What is actually happening?
RangeError: Maximum call stack size exceeded at Array.forEach ()
Internationalization related code:
Test assertion related code: