Explorar o código

bugfix: fix authority test

陈帅 %!s(int64=6) %!d(string=hai) anos
pai
achega
1e8238cdb9
Modificáronse 3 ficheiros con 2 adicións e 4 borrados
  1. 1 0
      jest.config.js
  2. 0 2
      src/components/Authorized/index.tsx
  3. 1 2
      src/utils/authority.ts

+ 1 - 0
jest.config.js

@@ -3,5 +3,6 @@ module.exports = {
   preset: 'jest-puppeteer',
   globals: {
     ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false,
+    localStorage: null,
   },
 };

+ 0 - 2
src/components/Authorized/index.tsx

@@ -1,11 +1,9 @@
 import Authorized from './Authorized';
-import AuthorizedRoute from './AuthorizedRoute';
 import Secured from './Secured';
 import check from './CheckPermissions';
 import renderAuthorize from './renderAuthorize';
 
 Authorized.Secured = Secured;
-Authorized.AuthorizedRoute = AuthorizedRoute;
 Authorized.check = check;
 
 const RenderAuthorize = renderAuthorize(Authorized);

+ 1 - 2
src/utils/authority.ts

@@ -2,9 +2,8 @@ import { reloadAuthorized } from './Authorized';
 
 // use localStorage to store the authority info, which might be sent from server in actual project.
 export function getAuthority(str?: string): string | string[] {
-  // return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
   const authorityString =
-    typeof str === 'undefined' ? localStorage.getItem('antd-pro-authority') : str;
+    typeof str === 'undefined' && localStorage ? localStorage.getItem('antd-pro-authority') : str;
   // authorityString could be admin, "admin", ["admin"]
   let authority;
   try {