diff --git a/lib/svgo-node.test.js b/lib/svgo-node.test.js
index 1b474e4af..2cf23dff0 100644
--- a/lib/svgo-node.test.js
+++ b/lib/svgo-node.test.js
@@ -156,56 +156,33 @@ describe('loadConfig', () => {
});
test('fails when specified config does not exist', async () => {
- try {
- await loadConfig('{}');
- expect.fail('Config is loaded successfully');
- } catch (error) {
- expect(error.message).toMatch(/Cannot find module/);
- }
+ await expect(loadConfig('{}')).rejects.toThrow(/Cannot find module/);
});
test('fails when exported config not an object', async () => {
- try {
- await loadConfig(path.join(fixtures, 'invalid-null.js'));
- expect.fail('Config is loaded successfully');
- } catch (error) {
- expect(error.message).toMatch(/Invalid config file/);
- }
- try {
- await loadConfig(path.join(fixtures, 'invalid-array.js'));
- expect.fail('Config is loaded successfully');
- } catch (error) {
- expect(error.message).toMatch(/Invalid config file/);
- }
- try {
- await loadConfig(path.join(fixtures, 'invalid-string.js'));
- expect.fail('Config is loaded successfully');
- } catch (error) {
- expect(error.message).toMatch(/Invalid config file/);
- }
+ await expect(
+ loadConfig(path.join(fixtures, 'invalid-null.js')),
+ ).rejects.toThrow(/Invalid config file/);
+ await expect(
+ loadConfig(path.join(fixtures, 'invalid-array.js')),
+ ).rejects.toThrow(/Invalid config file/);
+ await expect(
+ loadConfig(path.join(fixtures, 'invalid-string.js')),
+ ).rejects.toThrow(/Invalid config file/);
});
test('handles runtime errors properly', async () => {
- try {
- await loadConfig(path.join(fixtures, 'invalid-runtime.js'));
- expect.fail('Config is loaded successfully');
- } catch (error) {
- expect(error.message).toMatch(/plugins is not defined/);
- }
- try {
- await loadConfig(path.join(fixtures, 'invalid-runtime.mjs'));
- expect.fail('Config is loaded successfully');
- } catch (error) {
- expect(error.message).toMatch(/plugins is not defined/);
- }
+ await expect(
+ loadConfig(path.join(fixtures, 'invalid-runtime.js')),
+ ).rejects.toThrow(/plugins is not defined/);
+ await expect(
+ loadConfig(path.join(fixtures, 'invalid-runtime.mjs')),
+ ).rejects.toThrow(/plugins is not defined/);
});
test('handles MODULE_NOT_FOUND properly', async () => {
- try {
- await loadConfig(path.join(fixtures, 'module-not-found.js'));
- expect.fail('Config is loaded successfully');
- } catch (error) {
- expect(error.message).toMatch(/Cannot find module 'unknown-module'/);
- }
+ await expect(
+ loadConfig(path.join(fixtures, 'module-not-found.js')),
+ ).rejects.toThrow(/Cannot find module 'unknown-module'/);
});
});
diff --git a/lib/svgo.test.js b/lib/svgo.test.js
index 68fb8d7ea..468a894ab 100644
--- a/lib/svgo.test.js
+++ b/lib/svgo.test.js
@@ -267,13 +267,13 @@ test('plugin precision should override preset precision', () => {
});
test('provides informative error in result', () => {
+ expect.assertions(6);
const svg = `
`;
try {
optimize(svg, { path: 'test.svg' });
- expect(true).toEqual(false);
} catch (error) {
expect(error.name).toEqual('SvgoParserError');
expect(error.message).toEqual('test.svg:2:33: Unquoted attribute value');
@@ -285,13 +285,13 @@ test('provides informative error in result', () => {
});
test('provides code snippet in rendered error', () => {
+ expect.assertions(1);
const svg = `
`;
try {
optimize(svg, { path: 'test.svg' });
- expect(true).toEqual(false);
} catch (error) {
expect(error.toString())
.toEqual(`SvgoParserError: test.svg:2:29: Unquoted attribute value
@@ -306,6 +306,7 @@ test('provides code snippet in rendered error', () => {
});
test('supports errors without path', () => {
+ expect.assertions(1);
const svg = `