zhaoyongjie commented on a change in pull request #17698:
URL: https://github.com/apache/superset/pull/17698#discussion_r767084878



##########
File path: 
superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts
##########
@@ -21,40 +21,41 @@
 describe('logging', () => {
   beforeEach(() => {
     jest.resetModules();
-    // Explicit is better than implicit
-    console.warn = console.error = function mockedConsole(message) {
-      throw new Error(message);
-    };
+    jest.resetAllMocks();
   });
+
   it('should pipe to `console` methods', () => {
-    const { logging } = require('@superset-ui/core/src');
+    const { logging } = require('@superset-ui/core');
 
+    jest.spyOn(logging, 'debug').mockImplementation();
+    jest.spyOn(logging, 'log').mockImplementation();
+    jest.spyOn(logging, 'info').mockImplementation();
     expect(() => {
       logging.debug();
       logging.log();
       logging.info();
     }).not.toThrow();
-    expect(() => {
-      logging.warn('warn');
-    }).toThrow('warn');
-    expect(() => {
-      logging.error('error');
-    }).toThrow('error');

Review comment:
       mock console output, to make clear test output.
   
   ### before
   ```
   (superset) yongjie.zhao@:superset-frontend$ rm -rf coverage && npx jest 
--clearCache && NODE_ENV=test npx jest 
packages/superset-ui-core/test/utils/logging.test.ts
   Cleared /private/var/folders/10/0l8mvpf52jx6t3p68mndwn7m0000gn/T/jest_dx
    PASS  packages/superset-ui-core/test/utils/logging.test.ts (9.898 s)
     logging
       ✓ should pipe to `console` methods (4487 ms)
       ✓ should use noop functions when console unavailable (72 ms)
   
     console.debug
       undefined
   
         at packages/superset-ui-core/test/utils/logging.test.ts:33:15
   
     console.log
       undefined
   
         at packages/superset-ui-core/test/utils/logging.test.ts:34:15
   
     console.info
       undefined
   
         at packages/superset-ui-core/test/utils/logging.test.ts:35:15
   
   Test Suites: 1 passed, 1 total
   Tests:       2 passed, 2 total
   Snapshots:   0 total
   Time:        10.875 s
   Ran all test suites matching 
/packages\/superset-ui-core\/test\/utils\/logging.test.ts/i.
   ```
   
   
   ### After
   
   ```
   (superset) yongjie.zhao@:superset-frontend$ rm -rf coverage && npx jest 
--clearCache && NODE_ENV=test npx jest 
packages/superset-ui-core/test/utils/logging.test.ts
   Cleared /private/var/folders/10/0l8mvpf52jx6t3p68mndwn7m0000gn/T/jest_dx
    PASS  packages/superset-ui-core/test/utils/logging.test.ts (8.997 s)
     logging
       ✓ should pipe to `console` methods (4409 ms)
       ✓ should use noop functions when console unavailable (84 ms)
   
   Test Suites: 1 passed, 1 total
   Tests:       2 passed, 2 total
   Snapshots:   0 total
   Time:        9.707 s
   Ran all test suites matching 
/packages\/superset-ui-core\/test\/utils\/logging.test.ts/i.
   ```
   




-- 
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-unsubscr...@superset.apache.org

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



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

Reply via email to