Skip to content

Commit

Permalink
chore(everything-else): convert everything else to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Aug 16, 2019
1 parent 956a10c commit 41d6088
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
1 change: 1 addition & 0 deletions 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: [
Expand Down
67 changes: 44 additions & 23 deletions src/rules/__tests__/require-tothrow-message.test.ts
Expand Up @@ -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();",
Expand Down Expand Up @@ -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,
},
],
},
Expand Down

0 comments on commit 41d6088

Please sign in to comment.