From 1e8238cdb9b39cd2b6d6a51df87aec0d81ed0864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Mon, 21 Oct 2019 10:55:41 +0800 Subject: [PATCH] bugfix: fix authority test --- jest.config.js | 1 + src/components/Authorized/index.tsx | 2 -- src/utils/authority.ts | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/jest.config.js b/jest.config.js index 502fe338..049567c4 100644 --- a/jest.config.js +++ b/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, }, }; diff --git a/src/components/Authorized/index.tsx b/src/components/Authorized/index.tsx index 9bed7967..6703a46e 100644 --- a/src/components/Authorized/index.tsx +++ b/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); diff --git a/src/utils/authority.ts b/src/utils/authority.ts index fbb50193..d99659d1 100644 --- a/src/utils/authority.ts +++ b/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 {