mardi 29 octobre 2019

How to write snapshot test for SurveyScreen?

I am tyring to write snapshot test for a screen called SurveyScreen which uses react-native-simple-survey library.

In the render function of SurveyScreen.js, it looks like:

render() {
        return (
            <View style={styles.background}>
                <View style=>
                    <ScrollView contentContainerStyle= keyboardShouldPersistTaps='handled'>
                        <SimpleSurvey
                            survey={SurveyLocations[this.props.navigation.getParam('survey')]}
                            renderSelector={this.renderButton.bind(this)}
                            // containerStyle={styles.surveyContainer}
                            selectionGroupContainerStyle={styles.surveySelectionGroupContainer}
                            navButtonContainerStyle={styles.surveyNavButtonContainer}
                            renderPrevious={this.renderPreviousButton.bind(this)}
                            renderNext={this.renderNextButton.bind(this)}
                            renderFinished={this.renderFinishedButton.bind(this)}
                            renderQuestionText={this.renderQuestionText}
                            onSurveyFinished={(answers) => this.onSurveyFinished(answers)}
                            onAnswerSubmitted={(answer) => this.answerSubmit(answer)}
                            renderTextInput={this.renderTextBox}
                            renderDateInput={this.renderDateBox}
                            renderTimeInput={this.renderTimeBox}
                            renderNumericInput={this.renderNumericInput}
                            renderInfo={this.renderInfoText}
                        />
                    </ScrollView>
                </View>

            </View>
        );
    }

And this is the test file for it

import React from "react";
import SurveyScreen from "../app/screens/SurveyScreen"
import renderer from "react-test-renderer"

describe("<SurveyScreen/>", ()=>{
  it("SurveyScreen snapshot", ()=>{
    let wrapper = null;
    const spyNavigate = jest.fn();
    const props = {
      navaigation: {
        navigate: spyNavigate,
        state:{}
      }
    }
    const params = {
      token: 'someToken'
    }

    beforeEach(() => {
      wrapper = renderer.create(<SurveyScreen {...props} />)
      wrapper.setState({params: params})
    })
    expect(wrapper).toMatchSnapshot();
  });
});

In the auto-created snap file, there is nothing... What should I do to make it working? Thank you!

Aucun commentaire:

Enregistrer un commentaire