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

当调用render后再次调用render报错 #25

Closed
5kinna opened this issue May 22, 2019 · 5 comments
Closed

当调用render后再次调用render报错 #25

5kinna opened this issue May 22, 2019 · 5 comments

Comments

@5kinna
Copy link

5kinna commented May 22, 2019

版本号为:
"j-component":的版本号为:"^1.1.2",
"miniprogram-simulate": 的版本号为:"^1.0.1"

部分代码如下:
describe('badge render', () => {
it('default', () => {
const componentId =simulate.load('index', 'comp')
const component =simulate.render(componentId, {})
const parent = document.createElement('parent-wrapper')
component.attach(parent)
expect(component).toMatchSnapshot()
})
it('dot', () => {
const componentId = simulate.load('index', 'comp')
const component =simulate.render(componentId, {dot: true})
const parent = document.createElement('parent-wrapper-dot')
component.attach(parent)
expect(component).toMatchSnapshot()
})
})

结果为:
先调用一次render之后再调用render的时候,id为undefined,会报错。

@zhc525349965
Copy link

遇到了同样的问题,不知道什么时候解决?

@Genuifx
Copy link
Contributor

Genuifx commented Aug 6, 2019

同复现了问题

@Genuifx
Copy link
Contributor

Genuifx commented Aug 6, 2019

初步定位是require.cache没有被清除,然后新的组件无法重新调用Component方法进行注册,进而导致无法render

@JuneAndGreen
Copy link
Contributor

请问是使用 jest 么?如果是 jest 的话,得用 jest.resetModules() 的方式重置模块:jestjs/jest#5120

@JuneAndGreen
Copy link
Contributor

一般 nodejs 中 delete require.cache[xxxx] 是能正常工作的,但是部分测试框架会封装这个依赖系统,导致 delete require.cache[xxxx] 不生效。

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

No branches or pull requests

4 participants