Closed joeyzia closed 4 years ago
try addingimport "regenerator-runtime";
in your setupTests.js
src/setupTests.js
import Enzyme, { configure, shallow, mount, render } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import "regenerator-runtime";
configure({ adapter: new Adapter() });
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
};
export { shallow, mount, render };
export default Enzyme;
Does absolutely nothing.
Output:
> react-scripts test --verbose
FAIL src/components/auth/AuthButton.test.jsx
● Test suite failed to run
Error: No message was provided
Upon researching, realizing this is a silly error. You should be mocking the react-aad-msal
library for your tests and "intercepting" the library.
@joeyzia Hi, can you please expand on how you finally were able to create the tests (and mock the library) to test the authenticated and unauthenticated state?
i.e. can you show how you accomplished this:
You should be mocking the react-aad-msal library for your tests and "intercepting" the library.
Thanks
Library versions
react-aad-msal
: 2.3.4msal
: 1.2.1react-scripts
: 3.4.0enzyme
: 3.11.0Node Version
node
: v13.9.0npm
: 6.13.7Describe the bug When running
npm run test
/"test": "react-scripts test --verbose"
Jest is not able to run the test suite. Returns with an unclear error messageExpected behavior Should either fail with a clear error or pass successfully.
To Reproduce Steps to reproduce the behavior: