diff --git a/packages/grid/x-grid/src/XGrid.test.tsx b/packages/grid/x-grid/src/XGrid.test.tsx index 61d15d4579469..967d22c2e93a4 100644 --- a/packages/grid/x-grid/src/XGrid.test.tsx +++ b/packages/grid/x-grid/src/XGrid.test.tsx @@ -105,6 +105,15 @@ describe('', () => { container.firstChild.firstChild.firstChild, ); }); + + it('should not fail after scheduled tasks are run', async () => { + render( +
+ +
, + ); + await sleep(0); + }); }); describe('keyboard', () => { diff --git a/test/karma.conf.js b/test/karma.conf.js index ad97ab9c4d2f1..739c6ce48b0e3 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -56,6 +56,7 @@ module.exports = function setKarmaConfig(config) { 'process.env': { NODE_ENV: JSON.stringify('test'), CI: JSON.stringify(process.env.CI), + KARMA: JSON.stringify(true), }, }), ], diff --git a/test/karma.tests.js b/test/karma.tests.js index 3efa3970ad7a6..7312ca3881b8c 100644 --- a/test/karma.tests.js +++ b/test/karma.tests.js @@ -1,7 +1,55 @@ +/* eslint-env mocha */ import './utils/init'; -import consoleError from './utils/consoleError'; +import { createMochaHooks } from '@material-ui/monorepo/test/utils/mochaHooks'; -consoleError(); +const mochaHooks = createMochaHooks(window.Mocha); + +before(function beforeAllHook() { + mochaHooks.beforeAll.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +after(function afterAllHook() { + mochaHooks.afterAll.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +beforeEach(function beforeEachHook() { + mochaHooks.beforeEach.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +afterEach(function afterEachHook() { + mochaHooks.afterEach.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +// Ensure that uncaught exceptions between tests result in the tests failing. +// This works around an issue with mocha / karma-mocha, see +// https://github.com/karma-runner/karma-mocha/issues/227 +let pendingError = null; +let pendingErrorNotice = null; + +window.addEventListener('error', event => { + pendingError = event.error; + pendingErrorNotice = 'An uncaught exception was thrown between tests'; +}); + +window.addEventListener('unhandledrejection', event => { + pendingError = event.reason; + pendingErrorNotice = 'An uncaught promise rejection occurred between tests'; +}); + +afterEach(() => { + if (pendingError) { + console.error(pendingErrorNotice); + throw pendingError; + } +}); const packagesContext = require.context('../packages', true, /\.test\.tsx$/); packagesContext.keys().forEach(packagesContext); diff --git a/test/utils/consoleError.js b/test/utils/consoleError.js deleted file mode 100644 index 1b5aa26ebf762..0000000000000 --- a/test/utils/consoleError.js +++ /dev/null @@ -1,17 +0,0 @@ -/* eslint-disable no-console */ -// Makes sure the tests fails when a PropType validation fails. -function consoleError() { - console.error = (...args) => { - // Can't use log as karma is not displaying them. - console.info(...args); - throw new Error(...args); - }; - - console.warn = (...args) => { - // Can't use log as karma is not displaying them. - console.info(...args); - throw new Error(...args); - }; -} - -module.exports = consoleError; diff --git a/yarn.lock b/yarn.lock index 60a00fe97d0f7..fb4b9591bbe44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2735,8 +2735,8 @@ resolved "https://github.com/mui-org/material-ui.git#3c078f2f6943976fc4d3ed5d886bbfa0f391e4a2" "@material-ui/monorepo@https://github.com/mui-org/material-ui.git#next": - version "5.0.0-alpha.13" - resolved "https://github.com/mui-org/material-ui.git#13f3e9d8db81b40e1b08f43e4d45e37f3926c37d" + version "5.0.0-alpha.15" + resolved "https://github.com/mui-org/material-ui.git#c500fc3faf873142b9124319cebf728dd9a12cc5" "@material-ui/styles@^4.10.0": version "4.10.0"