тестирующий компонент с response-aad-msal - PullRequest
3 голосов
/ 18 февраля 2020

Мне нужно написать примеры модульных тестов для нижестоящих классов с помощью mocking response-aad-msal. как я могу издеваться над этим? Я читал, что энзим высмеивает компоненты, но я получаю ошибку как

console.error node_modules/react-aad-msal/dist/commonjs/Logger.js:69
      [ERROR] ClientAuthError: User login is required.

, которая, я думаю, не связана с модульным тестированием

    import React, { Component } from "react";
    import "./App.css";
    import { authProvider } from "./authProvider";
    import { AzureAD, AuthenticationState, IAzureADFunctionProps } from "react-aad-msal";
    import Home from "./pages/Home";
    import { ThemeProvider } from "styled-components";
    import { lightTheme } from "./themes";

    export default class App extends Component<{}, { theme: any }> {
      static displayName = App.name;
      constructor(props: any) {
        super(props);

        this.state = {
          theme: lightTheme
        };
      }

      render() {
        return (
          <AzureAD provider={authProvider} forceLogin>
            {({ authenticationState, accountInfo, error }: IAzureADFunctionProps) => {
              switch (authenticationState) {
                case AuthenticationState.Authenticated:
                  return (
                    <ThemeProvider theme={this.state.theme}>
                      <Home userInfo={accountInfo!=null? accountInfo.account.name: ""} />
                    </ThemeProvider>
                  );
                case AuthenticationState.Unauthenticated:
                  return (
                    <div>
                      {
                        <p>
                          <span>
                            An error {error} occured during authentication, please try
                            again!
                          </span>
                        </p>
                      }
                      <p>
                        <span>Hey stranger, you look new!</span>
                      </p>
                    </div>
                  );
                case AuthenticationState.InProgress:
                  return <p>Authenticating...</p>;
              }
            }}
          </AzureAD>
        );
      }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...