You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/11/03 07:45:25 UTC

[GitHub] [superset] zhaoyongjie commented on a diff in pull request #22015: refactor: Feature flags getter

zhaoyongjie commented on code in PR #22015:
URL: https://github.com/apache/superset/pull/22015#discussion_r1012577085


##########
superset-frontend/packages/superset-ui-core/test/utils/featureFlag.test.ts:
##########
@@ -16,48 +16,41 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
-import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
-
-const originalFeatureFlags = window.featureFlags;
-// eslint-disable-next-line no-console
-const originalConsoleError = console.error;
-const reset = () => {
-  window.featureFlags = originalFeatureFlags;
-  // eslint-disable-next-line no-console
-  console.error = originalConsoleError;
-};
+import mockConsole from 'jest-mock-console';
+import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
 
 it('returns false and raises console error if feature flags have not been initialized', () => {
-  // eslint-disable-next-line no-console
-  console.error = jest.fn();
-  delete (window as any).featureFlags;
-  expect(isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING)).toEqual(
-    false,
-  );
-
-  // eslint-disable-next-line no-console
-  expect(console.error).toHaveBeenNthCalledWith(
-    1,
-    'Failed to query feature flag ALLOW_DASHBOARD_DOMAIN_SHARDING (see error below)',
+  mockConsole();
+  Object.defineProperty(window, 'featureFlags', {
+    value: undefined,
+  });
+
+  expect(
+    isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
+  ).toBeFalsy();

Review Comment:
   Good point. I mistakenly thought that `toBeFalsy()` is a shortcut for `toEqual(false)`. will update



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org