From 41d608849f37936228002a78ba48a2ac94f3846a Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 4 Aug 2019 21:23:52 +1200 Subject: [PATCH] chore(everything-else): convert everything else to typescript --- babel.config.js | 1 + .../__tests__/require-tothrow-message.test.ts | 67 ++++++++++++------- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/babel.config.js b/babel.config.js index 65965928f..d167ade1f 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,5 +1,6 @@ 'use strict'; +// todo: https://github.com/babel/babel/issues/8529 :'( module.exports = { plugins: ['replace-ts-export-assignment'], presets: [ diff --git a/src/rules/__tests__/require-tothrow-message.test.ts b/src/rules/__tests__/require-tothrow-message.test.ts index 8c2bc7407..c750efef4 100644 --- a/src/rules/__tests__/require-tothrow-message.test.ts +++ b/src/rules/__tests__/require-tothrow-message.test.ts @@ -12,55 +12,74 @@ ruleTester.run('require-tothrow-message', rule, { // String "expect(() => { throw new Error('a'); }).toThrow('a');", "expect(() => { throw new Error('a'); }).toThrowError('a');", - `test('string', async () => { + ` + test('string', async () => { const throwErrorAsync = async () => { throw new Error('a') }; await expect(throwErrorAsync()).rejects.toThrow('a'); await expect(throwErrorAsync()).rejects.toThrowError('a'); - })`, + }) + `, // Template literal "const a = 'a'; expect(() => { throw new Error('a'); }).toThrow(`${a}`);", "const a = 'a'; expect(() => { throw new Error('a'); }).toThrowError(`${a}`);", - `test('Template literal', async () => { + ` + test('Template literal', async () => { const a = 'a'; const throwErrorAsync = async () => { throw new Error('a') }; await expect(throwErrorAsync()).rejects.toThrow(\`\${a}\`); await expect(throwErrorAsync()).rejects.toThrowError(\`\${a}\`); - })`, + }) + `, // Regex "expect(() => { throw new Error('a'); }).toThrow(/^a$/);", "expect(() => { throw new Error('a'); }).toThrowError(/^a$/);", - `test('Regex', async () => { + ` + test('Regex', async () => { const throwErrorAsync = async () => { throw new Error('a') }; await expect(throwErrorAsync()).rejects.toThrow(/^a$/); await expect(throwErrorAsync()).rejects.toThrowError(/^a$/); - })`, + }) + `, // Function - "expect(() => { throw new Error('a'); })" + - ".toThrow((() => { return 'a'; })());", - "expect(() => { throw new Error('a'); })" + - ".toThrowError((() => { return 'a'; })());", - `test('Function', async () => { + "expect(() => { throw new Error('a'); }).toThrow((() => { return 'a'; })());", + "expect(() => { throw new Error('a'); }).toThrowError((() => { return 'a'; })());", + ` + test('Function', async () => { const throwErrorAsync = async () => { throw new Error('a') }; const fn = () => { return 'a'; }; await expect(throwErrorAsync()).rejects.toThrow(fn()); await expect(throwErrorAsync()).rejects.toThrowError(fn()); - })`, + }) + `, // Allow no message for `not`. "expect(() => { throw new Error('a'); }).not.toThrow();", "expect(() => { throw new Error('a'); }).not.toThrowError();", - `test('Allow no message for "not"', async () => { + ` + test('Allow no message for "not"', async () => { const throwErrorAsync = async () => { throw new Error('a') }; await expect(throwErrorAsync()).resolves.not.toThrow(); await expect(throwErrorAsync()).resolves.not.toThrowError(); - })`, + }) + `, 'expect(a);', ], invalid: [ + { + code: "expect(() => { throw new Error('a'); })[`toThrow`]();", + errors: [ + { + messageId: 'requireRethrow', + data: { propertyName: 'toThrow' }, + column: 41, + line: 1, + }, + ], + }, // Empty toThrow { code: "expect(() => { throw new Error('a'); }).toThrow();", @@ -88,23 +107,25 @@ ruleTester.run('require-tothrow-message', rule, { // Empty rejects.toThrow / rejects.toThrowError { - code: `test('empty rejects.toThrow', async () => { - const throwErrorAsync = async () => { throw new Error('a') }; - await expect(throwErrorAsync()).rejects.toThrow(); - await expect(throwErrorAsync()).rejects.toThrowError(); - })`, + code: ` + test('empty rejects.toThrow', async () => { + const throwErrorAsync = async () => { throw new Error('a') }; + await expect(throwErrorAsync()).rejects.toThrow(); + await expect(throwErrorAsync()).rejects.toThrowError(); + }) + `, errors: [ { messageId: 'requireRethrow', data: { propertyName: 'toThrow' }, - column: 49, - line: 3, + column: 51, + line: 4, }, { messageId: 'requireRethrow', data: { propertyName: 'toThrowError' }, - column: 49, - line: 4, + column: 51, + line: 5, }, ], },