test: make negative tests fail when nothing throws
Merged
SR
10h ago+31+31+01234567890123456789-95-95-01234567890123456789
Summary
14 "should throw" tests passed even when nothing threw. They used try { return await minify() } catch { expect(err)… }, so a resolved promise skipped the assertion. They now assert the rejection:
-try {
- return await minify(settings);
-} catch (err) {
- return expect(err).not.toBeNull();
-}
+await expect(minify(settings)).rejects.toThrow("cssnano minification failed");
| Package | Assertion |
|---|---|
| core (6), esbuild type check | exact node-minify message |
| cssnano | "cssnano minification failed" |
| lightningcss | SyntaxError (the library's message text varies between versions) |
| esbuild js, google-closure-compiler, swc, terser, uglify-js | .toThrow() with no argument (third-party messages) |
Tests only. No changeset.
Evidence
- Before: giving the "no input" core test an
inputleft it green.
After: the same edit fails it withpromise resolved … instead of rejecting. - With
tests/fixtures/css-errorsrenamed, the cssnano and lightningcss tests now fail (they gotNo content provided). Before, any error passed them. bun run test: 71 files, 1080 tests pass. Lint, typecheck,ci-guard-type-suppressions.shpass.
Merge Danger
Door: two-way
Blast Radius: tests
No runtime code changes.
Summary by cubic
Updates 14 "should throw" tests so they fail when minify() resolves instead of rejecting. The old try/catch pattern returned successfully on a resolved promise and skipped the assertion; tests now use expect(...).rejects.toThrow(...).
Assertions
- Core, cssnano, esbuild, and google-closure-compiler assert their exact error message.
- lightningcss asserts a
SyntaxErrorsince the library message varies between versions. - swc, terser, and uglify-js assert that any error is thrown, as third-party messages are not stable.
Tests only, no changeset.