-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
@tarojs/mobx相关的控件,用jest测试时存在问题 #1850
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
看上去是没有配置好,提供一下你的工程的相关内容吧 |
@neoscript99 来个完整的 demo,[email protected] |
import Nerv from 'nervjs'
import { renderToString } from 'nerv-server'
import { Provider } from '@tarojs/mobx'
import stores from '../../stores'
import BaseInfoTest from '../../../.temp/components/BaseInfoTest'
import BaseInfo from '../../../.temp/components/BaseInfo'
jest.mock('../../utils/database')
const { baseInfoStore, paramStore } = stores
describe('ui test', () => {
it('no mobx', () => {
const component = renderToString(
<BaseInfoTest baseInfoStore={baseInfoStore} paramStore={paramStore} />
)
expect(component)
.toMatchSnapshot()
})
it('with mobx', () => {
const component = renderToString(
<Provider store={stores}>
<BaseInfo baseInfoStore={baseInfoStore} paramStore={paramStore} />
</Provider>
)
expect(component)
.toMatchSnapshot()
})
}) |
@neoscript99 所以来一个完整的 demo 嘛 ^ _ ^ |
@nanjingboy 这个jest测试环境有点麻烦,需要点时间,我整理看看 |
function renderVNodeToString (vnode, parent, context, firstChild) {
const { tagName, props, children } = vnode
if (isVText(vnode)) {
return encodeEntities(vnode.text)
} else if (isVNode(vnode)) {
let renderedString = `<${tagName}`
let html
if (!isNullOrUndef(props)) {
for (const prop in props) {
const value = props[prop]
if (skipAttributes[prop]) {
continue
}
if (prop === 'dangerouslySetInnerHTML') {
html = value.__html
} else if (prop === 'style') {
renderedString += ` style="${renderStylesToString(value)}"`
} else if (prop === 'class' || prop === 'className') {
renderedString += ` class="${isString(value) ? value : hashToClassName(value)}"`
} else if (prop === 'defaultValue') {
if (!props.value) {
renderedString += ` value="${escapeText(value)}"`
}
} else if (prop === 'defaultChecked') {
if (!props.checked) {
renderedString += ` checked="${value}"`
}
} else {
if (isString(value)) {
renderedString += ` ${prop}="${escapeText(value)}"`
} else if (isNumber(value)) {
renderedString += ` ${prop}="${value}"`
} else if (value === true) {
renderedString += ` ${prop}`
}
}
}
}
if (isVoidElements[tagName]) {
renderedString += `/>`
} else {
renderedString += `>`
if (!isInvalid(children)) {
if (isString(children)) {
renderedString += children === '' ? ' ' : escapeText(children)
} else if (isNumber(children)) {
renderedString += children + ''
} else if (isArray(children)) {
for (let i = 0, len = children.length; i < len; i++) {
const child = children[i]
if (isString(child)) {
renderedString += child === '' ? ' ' : escapeText(child)
} else if (isNumber(child)) {
renderedString += child
} else if (!isInvalid(child)) {
renderedString += renderVNodeToString(
child,
vnode,
context,
i === 0
)
}
}
} else {
renderedString += renderVNodeToString(children, vnode, context, true)
}
} else if (html) {
renderedString += html
}
if (!isVoidElements[tagName]) {
renderedString += `</${tagName}>`
}
}
return renderedString
} else if (isWidget(vnode)) {
const { ComponentType: type } = vnode
const instance = new type(props, context)
instance._disable = true
if (isFunction(instance.getChildContext)) {
context = assign(assign({}, context), instance.getChildContext())
}
instance.context = context
if (isFunction(instance.componentWillMount)) {
instance.componentWillMount()
}
const nextVnode = instance.render(props, instance.state, context)
if (isInvalid(nextVnode)) {
return '<!--!-->'
}
return renderVNodeToString(nextVnode, vnode, context, true)
} else if (isStateLess(vnode)) {
const nextVnode = tagName(props, context)
if (isInvalid(nextVnode)) {
return '<!--!-->'
}
return renderVNodeToString(nextVnode, vnode, context, true)
}
} |
问题我找到了
如何解决,@nanjingboy if (isStateless(vnode)) {
const rendered = type(props, context)
return renderVNodeToString(rendered, vnode, context, isSvg)
} |
@neoscript99 知道了,稍后我提一个 PR |
luckyadam
pushed a commit
that referenced
this issue
Jan 8, 2019
@neoscript99 Tom 兄已提交 PR,可以下个版本试试 |
close via 2aaf6d7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
复现步骤
报错信息
系统信息
The text was updated successfully, but these errors were encountered: