Фермент: «Ошибка: метод« text »предназначен для запуска на 1 узле. Вместо него найдено 0». - PullRequest
0 голосов
/ 04 октября 2019

Я тоже пытаюсь добавить модульное тестирование в проект, над которым я работаю, используя Enzyme. Мне удалось настроить базовый тест, однако, когда я пытаюсь его запустить, я получаю следующую ошибку: «Метод« text »предназначен для запуска на 1 узле. Вместо него найдено 0».

Я изучал различные онлайн-уроки, а также ответы SO на похожие вопросы, но не могу найти ничего, что могло бы помочь. Я также пробовал console.log-обертку, которая возвращает:

<Connect(withRouter(WithStyles(SignIn))) >

Проверяемый код;

class SignIn extends Component {

//Removed unnecessary code for expediency

  render() {
    const { classes, loading } = this.props;
    const {
      values,
      touched,
      errors,
      isValid,
    } = this.state;

    const hasError = field => !!(touched[field] && errors[field]);
    const { store } = configureStore();

    return (
      <Provider store={store}>
        <div className={classes.root}>
          <Grid
            className={classes.grid}
            container
          >
            <Grid
              className={classes.quoteWrapper}
              item
              lg={5}
            >
              <div className={classes.quote}>
                <div className={classes.quoteInner}>
                  <Typography
                    className={classes.quoteText}
                    variant="h1"
                  >
                    We work with your business to provide a range of innovative
                    and bespoke software solutions.
                  </Typography>
                </div>
              </div>
            </Grid>
            <Grid
              className={classes.content}
              item
              lg={7}
              xs={12}
            >
              <div className={classes.content}>
                <div className={classes.contentBody}>
                  <form className={classes.form}>


                     <p>
                      <Typography
                        className={classes.title}
                        variant="h2"
                      >
                        Sign in
                      </Typography>
                    </p>



                    <div className={classes.fields}>
                      <TextField
                        className={classes.textField}
                        error={hasError('username')}
                        helperText={
                          hasError('username') ? errors.username[0] : null
                        }
                        label="User name"
                        name="username"
                        onChange={event =>
                          this.handleFieldChange('username', event.target.value)
                        }
                        onKeyPress={this.handleKeyPress}
                        type="text"
                        value={values.username}
                        variant="outlined"
                      />
                      <TextField
                        className={classes.textField}
                        error={hasError('password')}
                        helperText={
                          hasError('password') ? errors.password[0] : null
                        }
                        label="Password"
                        name="password"
                        onChange={event =>
                          this.handleFieldChange('password', event.target.value)
                        }
                        onKeyPress={this.handleKeyPress}
                        type="password"
                        value={values.password}
                        variant="outlined"
                      />
                    </div>
                    {loading ? (
                      <CircularProgress className={classes.progress}/>
                    ) : (
                      <Button
                        className={classes.signInButton}
                        color="primary"
                        disabled={!isValid}
                        onClick={this.handleSignIn}
                        size="large"
                        variant="contained"
                      >
                        Sign in now
                      </Button>
                    )}
                    <Typography
                      className={classes.resetPassword}
                      variant="body1"
                    >
                      Have you forgotten your password?{' '}
                      <Link
                        className={classes.resetPasswordURL}
                        to="/reset-password"
                      >
                        Reset it
                      </Link>
                    </Typography>
                  </form>
                </div>
              </div>
            </Grid>
          </Grid>
        </div>
      </Provider>
    );
  }
}

SignIn.propTypes = {
  className: PropTypes.string,
  classes: PropTypes.object.isRequired,
  dispatch: PropTypes.func.isRequired,
  history: PropTypes.object.isRequired,
  loading: PropTypes.bool.isRequired,
  user: PropTypes.object.isRequired
};

const mapStateToProps = state => ({
  loading: state.authReducer.loadingKeys.includes(dataConstants.loading.main),
  user: state.authReducer.user
});

export default connect(mapStateToProps)(compose(
  withRouter,
  withStyles(styles)
)(SignIn));

И вот мой тест:

describe('SignIn component', () => {
  it('starts with a count of 0', () => {
    const wrapper = shallow(
      <Provider store={store}>
        <SignIn/>;
      </Provider>
    ).dive();
    let wrapperDebug = wrapper.debug();
    console.log(wrapperDebug);
    const text = wrapper.find('p').text();
    expect(text).toEqual('Sign in');

  });

});

Тест должен найти типографику в окружении p (я оставил несколько строк в моем коде с обеих сторон для выделения этой области) и сравнить найденный текст с ожидаемым значением. Заранее спасибо за любую помощь!

...