Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded at Array.forEach #647

Closed
BTCLTC opened this issue May 24, 2018 · 10 comments
Closed

RangeError: Maximum call stack size exceeded at Array.forEach #647

BTCLTC opened this issue May 24, 2018 · 10 comments

Comments

@BTCLTC
Copy link

BTCLTC commented May 24, 2018

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 (node_modules/_@[email protected]@/dist/vue-test-utils.js:3006:16)

What is expected?

PASS

What is actually happening?

RangeError: Maximum call stack size exceeded
at Array.forEach ()

  at orderDeps (node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3006:16)
      at Array.forEach (<anonymous>)
  at node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3011:14
      at Array.forEach (<anonymous>)
  at orderDeps (node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3006:16)
      at Array.forEach (<anonymous>)
  at node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3011:14
      at Array.forEach (<anonymous>)
  at orderDeps (node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3006:16)
      at Array.forEach (<anonymous>)
  at node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3011:14
      at Array.forEach (<anonymous>)
  at orderDeps (node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3006:16)
      at Array.forEach (<anonymous>)
  at node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3011:14
      at Array.forEach (<anonymous>)
  at orderDeps (node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3006:16)
      at Array.forEach (<anonymous>)
  at node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3011:14
      at Array.forEach (<anonymous>)
  at orderDeps (node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3006:16)
      at Array.forEach (<anonymous>)
  at node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3011:14
      at Array.forEach (<anonymous>)
  at orderDeps (node_modules/_@[email protected]@@vue/test-utils/dist/vue-test-utils.js:3006:16)
      at Array.forEach (<anonymous>)

Internationalization related code:

import VueI18n from 'vue-i18n';
import localVue from './localVue';
import en from 'iview/dist/locale/en-US';
import zh from 'iview/dist/locale/zh-CN';
import zhTW from 'iview/dist/locale/zh-TW';
import viVI from 'iview/dist/locale/vi-VN';
import zhCn from '@/assets/lang/zh-cn';
import zhTw from '@/assets/lang/zh-tw';
import enUS from '@/assets/lang/en-us';
import vi from '@/assets/lang/vi-vi';

localVue.use(VueI18n);

const messages = {
'zh-CN': Object.assign(zhCn, zh),
'zh-TW': Object.assign(zhTw, zhTW),
'en-US': Object.assign(enUS, en),
'vi-VI': Object.assign(viVI, vi),
};

const i18n = new VueI18n({
locale: 'zh-CN',
messages
});

export default i18n;

Test assertion related code:

import VueRouter from 'vue-router';
import iView from 'iview';
import { mount, localVue, i18n } from './utils';

import Register from '@/components/register/register.vue'; 
import method from '@/utils/vueExtend/method';
import filters from '@/utils/vueExtend/filters';

localVue.use(iView);
localVue.use(VueRouter);
localVue.use(method);
localVue.use(filters);

const wrapper = mount(Register, {
  i18n,
  localVue,
  stubs: ['router-link', 'router-view']
});

describe('register.vue', () => {
  it('test data is edit', () => {
    wrapper.setData({
    regPhoneFromData: {
      telephone: '13800138000',
      auth_code: '123456',
      password: 'qaz123456',
      confirmPwd: 'qaz123456'
    }
  });
  expect(wrapper.vm.regPhoneFromData).toEqual({
    telephone: '13800138000',
    auth_code: '123456',
    password: 'qaz123456',
    confirmPwd: 'qaz123456'
  });
});
});
@BTCLTC
Copy link
Author

BTCLTC commented May 26, 2018

What should I do?I use Vue but not localVue,it's can work。

@BTCLTC
Copy link
Author

BTCLTC commented May 26, 2018

@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

@eddyerburgh
Copy link
Member

This is a bug caused by setting watchers to sync. I'm looking into a fix, one solution is a change to Vue core—vuejs/vue#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()
  })
})

@BTCLTC
Copy link
Author

BTCLTC commented Jun 3, 2018

@eddyerburgh Thank you. It's done.

@maksnester
Copy link

maksnester commented Jan 15, 2019

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">

@eddyerburgh
Copy link
Member

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?

@maksnester
Copy link

@eddyerburgh it works fine with correct import, so I don't think it's really necessary.

@Overdrivr
Copy link

@eddyerburgh This is still a problem with latest vue 2.5.22, workaround is still required. Is this normal ?

@eddyerburgh
Copy link
Member

@Overdrivr Could you open a new issue with a minimal reproduction that I can debug?

@Overdrivr
Copy link

I'm swamped with work as of now, but I'll try ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants