-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
console.assert not throwing with v22.4.0 #5634
Comments
/cc @ranyitz |
We had a discussion regarding the subject on #5576.
That's what we're doing and I think that it's better when /cc @thymikee |
Might be worth a flag? Not sure |
A testing environment (Jest) being more strict than the final running environment (browser) is not a bad thing and probably wanted. The browser has a different goal: make the end user happy VS a testing environment validates code is rock solid. Do we want a unit test to succeed even if the code tested contains an assert that fails? Did you have developers complaining about console.assert() throwing in Jest and not behaving exactly like the browser? My use case: function removeItem(itemName) {
console.assert(list[itemName] !== undefined, `Unknown item '${itemName}'`);
delete this[itemName];
}
test('removeItem() with unknown item', () => {
expect(() => removeItem('unknown')).toThrow("Unknown item 'unknown'");
}); These "guards" should never fail in production and can/should be stripped away from the production code. |
My two cents on that:
|
@mjesun Actually the default env is |
😆 I'm too used to my internal stuff |
Agree with @mjesun and @thymikee, by default the semantics of assert should match the environment being emulated. Sounds like we broke that in node but it's working as expected in jsdom @tkrotoff to get the assert semantics you're looking for in a jsdom environment, you can override console.assert = (statement, message) => {
if (!statement) throw new Error(message);
}; That will fail tests like this: |
This is what I do by redirecting console.assert to Node' assert: // File jest.setup.ts
import assert from 'assert';
console.assert = assert; // File jest.config.js
const config = {
setupFiles: ['./jest.setup.ts']
};
module.exports = config; |
See console.assert not throwing with v22.4.0 jestjs/jest#5634
See console.assert not throwing with v22.4.0 jestjs/jest#5634
See console.assert not throwing with v22.4.0 jestjs/jest#5634
See console.assert not throwing with v22.4.0 jestjs/jest#5634
See console.assert not throwing with v22.4.0 jestjs/jest#5634
See console.assert not throwing with v22.4.0 jestjs/jest#5634
|
I agree, thanks for following up! |
…nding of completion emails regardless of test name https://bugs.webkit.org/show_bug.cgi?id=221712 Patch by Roy Reapor <rreapor@apple.com> on 2021-02-12 Reviewed by Dewei Zhu. Rule `platforms` and `tests` can be undefined, an empty array, or an array of strings. Undefined will match everything. Empty array will match nothing. Array of strings will match items in the array. Rule will not match if either `tests` or `platforms` is an empty array. * tools/js/analysis-results-notifier.js: (AnalysisResultsNotifier._validateRules.isUnderfinedOrEmptyArrayOrArrayOfStrings): - `platforms` and `tests` can now be undefined or an empty array officially (AnalysisResultsNotifier._validateRules): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (jestjs/jest#5634) - both rule `platforms` and `tests` must pass `isUnderfinedOrEmptyArrayOrArrayOfStrings()`. previously, rules like `{tests: [1, 3], platforms: ['speedometer']}` passes validation. (AnalysisResultsNotifier._applyUpdate): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (jestjs/jest#5634) (AnalysisResultsNotifier._validateRules.isNonemptyArrayOfStrings): Deleted. * unit-tests/analysis-results-notifier-tests.js: - added a bunch of unittests - specify the exact regex match for `assert.throws()` and `assert.doesNotThrow()` argument. Canonical link: https://commits.webkit.org/234049@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
…nding of completion emails regardless of test name https://bugs.webkit.org/show_bug.cgi?id=221712 Patch by Roy Reapor <rreapor@apple.com> on 2021-02-12 Reviewed by Dewei Zhu. Rule `platforms` and `tests` can be undefined, an empty array, or an array of strings. Undefined will match everything. Empty array will match nothing. Array of strings will match items in the array. Rule will not match if either `tests` or `platforms` is an empty array. * tools/js/analysis-results-notifier.js: (AnalysisResultsNotifier._validateRules.isUnderfinedOrEmptyArrayOrArrayOfStrings): - `platforms` and `tests` can now be undefined or an empty array officially (AnalysisResultsNotifier._validateRules): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (jestjs/jest#5634) - both rule `platforms` and `tests` must pass `isUnderfinedOrEmptyArrayOrArrayOfStrings()`. previously, rules like `{tests: [1, 3], platforms: ['speedometer']}` passes validation. (AnalysisResultsNotifier._applyUpdate): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (jestjs/jest#5634) (AnalysisResultsNotifier._validateRules.isNonemptyArrayOfStrings): Deleted. * unit-tests/analysis-results-notifier-tests.js: - added a bunch of unittests - specify the exact regex match for `assert.throws()` and `assert.doesNotThrow()` argument. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@272813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
According to NodeJS v8.x doc:
console.assert(false)
does not throw with v22.4.0 (was working at least with v22.1.4):The text was updated successfully, but these errors were encountered: