3

I'm trying to test my SpringComponent. This component uses react-spring for animations. When I run my test I get the following error:

"Jest encountered an unexpected token".

If I comment my Spring code the error disappears and my test passes.

This is the testing code:

import React from "react";
import SpringComponent from "../components/SpringComponent";


test('renders without crashing', () => {
    expect(true).toBeTruthy();
});

And the SpringComponent code:

import React from "react";
import {Spring} from "react-spring/renderprops-universal";

class SpringComponent extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            content: this.props.content,
        }
    }

    componentDidUpdate(prevProps) {
    }

    render() {
        let content = this.state.content;
        console.log("content: " + content);
        return <div>
            <Spring
                from={{opacity: 0}}
                to={{opacity: 1}}
            >
                {props => <div style={props}>
                    {content}
                </div>}
            </Spring>
        </div>
    }

}

export default SpringComponent;

I wonder what I must do to test this code. Should I mock something?

Tim MG
  • 426
  • 5
  • 17

0 Answers0