diff --git a/.eslintrc.json b/.eslintrc.json index 02206f92a1a463..a3de6444e0e62a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -26,8 +26,7 @@ "extends": ["plugin:jest/recommended"], "rules": { "jest/expect-expect": "off", - "jest/no-disabled-tests": "off", - "jest/no-try-expect": "off" + "jest/no-disabled-tests": "off" } }, { "files": ["**/__tests__/**"], "env": { "jest": true } }, diff --git a/test/integration/create-next-app/index.test.js b/test/integration/create-next-app/index.test.js index 373c409d64dd0f..f6f17233cce5a4 100644 --- a/test/integration/create-next-app/index.test.js +++ b/test/integration/create-next-app/index.test.js @@ -45,6 +45,7 @@ describe('create next app', () => { try { await runStarter(cwd, projectName) } catch (e) { + // eslint-disable-next-line jest/no-try-expect expect(e.stdout).toMatch(/contains files that could conflict/) } }) @@ -76,6 +77,7 @@ describe('create next app', () => { try { await run(cwd, projectName, '--example', 'not a real example') } catch (e) { + // eslint-disable-next-line jest/no-try-expect expect(e.stderr).toMatch(/Could not locate an example named/i) } expect( diff --git a/test/isolated/config.test.js b/test/isolated/config.test.js index 0607992907152b..ef0401d9733d4e 100644 --- a/test/isolated/config.test.js +++ b/test/isolated/config.test.js @@ -66,16 +66,12 @@ describe('config', () => { }) it('Should throw when an invalid target is provided', () => { - try { + expect(() => { loadConfig( PHASE_DEVELOPMENT_SERVER, join(__dirname, '_resolvedata', 'invalid-target') ) - // makes sure we don't just pass if the loadConfig passes while it should fail - throw new Error('failed') - } catch (err) { - expect(err.message).toMatch(/Specified target is invalid/) - } + }).toThrow(/Specified target is invalid/) }) it('Should pass when a valid target is provided', () => { @@ -87,18 +83,14 @@ describe('config', () => { }) it('Should throw an error when next.config.js is not present', () => { - try { + expect(() => loadConfig( PHASE_DEVELOPMENT_SERVER, join(__dirname, '_resolvedata', 'typescript-config') ) - // makes sure we don't just pass if the loadConfig passes while it should fail - throw new Error('failed') - } catch (err) { - expect(err.message).toMatch( - /Configuring Next.js via .+ is not supported. Please replace the file with 'next.config.js'./ - ) - } + ).toThrow( + /Configuring Next.js via .+ is not supported. Please replace the file with 'next.config.js'/ + ) }) it('Should not throw an error when two versions of next.config.js are present', () => { diff --git a/test/isolated/require-page.test.js b/test/isolated/require-page.test.js index d8859bc7ac9f29..59d3374fb2e62d 100644 --- a/test/isolated/require-page.test.js +++ b/test/isolated/require-page.test.js @@ -25,6 +25,7 @@ describe('pageNotFoundError', () => { try { throw pageNotFoundError('test') } catch (err) { + // eslint-disable-next-line jest/no-try-expect expect(err.code).toBe('ENOENT') } }) @@ -89,6 +90,7 @@ describe('requirePage', () => { try { await requirePage('/../../test', distDir) } catch (err) { + // eslint-disable-next-line jest/no-try-expect expect(err.code).toBe('ENOENT') } }) @@ -98,6 +100,7 @@ describe('requirePage', () => { try { await requirePage('/non-existent', distDir) } catch (err) { + // eslint-disable-next-line jest/no-try-expect expect(err.code).toBe('ENOENT') } }) @@ -107,6 +110,7 @@ describe('requirePage', () => { try { await requirePage('/non-existent-child', distDir) } catch (err) { + // eslint-disable-next-line jest/no-try-expect expect(err.code).toBe('MODULE_NOT_FOUND') } })