Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

TypeError: vNode.type is not a function #21

Open
saifeiLee opened this issue Jul 21, 2020 · 0 comments
Open

TypeError: vNode.type is not a function #21

saifeiLee opened this issue Jul 21, 2020 · 0 comments

Comments

@saifeiLee
Copy link

Hello. I want to add unit test for my inferno component. And I trapped by a error: TypeError: vNode.type is not a function.
Here is my component:

import { PureComponent, ComponentProps } from '@enow/enow-kernel';
import { getStyle, getBody, getWrapper } from './renderUtil';

class TextElement extends PureComponent<ComponentProps, any> {
  public render () {
    const { model } = this.props;
    const slideId = this.context.currentSlideId;
    const style = getStyle({model});
    const textChunk = getBody({model});
    const wrapper = getWrapper(model, style, textChunk);
    return (
      <div
        style={style}
        class="enow__text"
        id={`enow-text-${slideId}-${model.get('id')}`}
      >
        {wrapper || textChunk}
        {this.props.children}
      </div>
    );
  }
}

export default TextElement;

Here is my test case:

/**
 * 该用例存在问题,产生的snapshot不可用,若删去mock,报错:vNode.type is not a function
 */
import TextElement from '../src/renderer';
import { mount } from 'enzyme';
import { fromJS } from '@enow/enow-component-utils';

jest.mock('@enow/enow-kernel');

const mockModelStr = `{foo: 'bar'}`;
const mockModelObj = fromJS(JSON.parse(mockModelStr));

jest.mock('../src/textRun', () => ({}));

describe('TextElement', () => {
  it('TextElement should work well', () => {
    const wrapper = mount(<TextElement model={mockModelObj} />);
    expect(wrapper).toBeTruthy();
    expect(wrapper).toMatchSnapshot()
  });
});

@enow/enow-kernel is a inner module, I mock it:

import { Component } from '@cvte/inferno-with-canvas';

module.exports = {
    PureComponent: Component,
    ComponentProps: {}
}

This is error info that console output:
image

Could anyone please give me some advice? Thanks in advance~~~

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

No branches or pull requests

1 participant