Unverified Commit ccea1c01 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Enable jest/no-try-expect (#13124)

parent a17ace8e
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
"extends": ["plugin:jest/recommended"], "extends": ["plugin:jest/recommended"],
"rules": { "rules": {
"jest/expect-expect": "off", "jest/expect-expect": "off",
"jest/no-disabled-tests": "off", "jest/no-disabled-tests": "off"
"jest/no-try-expect": "off"
} }
}, },
{ "files": ["**/__tests__/**"], "env": { "jest": true } }, { "files": ["**/__tests__/**"], "env": { "jest": true } },
......
...@@ -45,6 +45,7 @@ describe('create next app', () => { ...@@ -45,6 +45,7 @@ describe('create next app', () => {
try { try {
await runStarter(cwd, projectName) await runStarter(cwd, projectName)
} catch (e) { } catch (e) {
// eslint-disable-next-line jest/no-try-expect
expect(e.stdout).toMatch(/contains files that could conflict/) expect(e.stdout).toMatch(/contains files that could conflict/)
} }
}) })
...@@ -76,6 +77,7 @@ describe('create next app', () => { ...@@ -76,6 +77,7 @@ describe('create next app', () => {
try { try {
await run(cwd, projectName, '--example', 'not a real example') await run(cwd, projectName, '--example', 'not a real example')
} catch (e) { } catch (e) {
// eslint-disable-next-line jest/no-try-expect
expect(e.stderr).toMatch(/Could not locate an example named/i) expect(e.stderr).toMatch(/Could not locate an example named/i)
} }
expect( expect(
......
...@@ -66,16 +66,12 @@ describe('config', () => { ...@@ -66,16 +66,12 @@ describe('config', () => {
}) })
it('Should throw when an invalid target is provided', () => { it('Should throw when an invalid target is provided', () => {
try { expect(() => {
loadConfig( loadConfig(
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
join(__dirname, '_resolvedata', 'invalid-target') join(__dirname, '_resolvedata', 'invalid-target')
) )
// makes sure we don't just pass if the loadConfig passes while it should fail }).toThrow(/Specified target is invalid/)
throw new Error('failed')
} catch (err) {
expect(err.message).toMatch(/Specified target is invalid/)
}
}) })
it('Should pass when a valid target is provided', () => { it('Should pass when a valid target is provided', () => {
...@@ -87,18 +83,14 @@ describe('config', () => { ...@@ -87,18 +83,14 @@ describe('config', () => {
}) })
it('Should throw an error when next.config.js is not present', () => { it('Should throw an error when next.config.js is not present', () => {
try { expect(() =>
loadConfig( loadConfig(
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
join(__dirname, '_resolvedata', 'typescript-config') join(__dirname, '_resolvedata', 'typescript-config')
) )
// makes sure we don't just pass if the loadConfig passes while it should fail ).toThrow(
throw new Error('failed') /Configuring Next.js via .+ is not supported. Please replace the file with 'next.config.js'/
} catch (err) { )
expect(err.message).toMatch(
/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', () => { it('Should not throw an error when two versions of next.config.js are present', () => {
......
...@@ -25,6 +25,7 @@ describe('pageNotFoundError', () => { ...@@ -25,6 +25,7 @@ describe('pageNotFoundError', () => {
try { try {
throw pageNotFoundError('test') throw pageNotFoundError('test')
} catch (err) { } catch (err) {
// eslint-disable-next-line jest/no-try-expect
expect(err.code).toBe('ENOENT') expect(err.code).toBe('ENOENT')
} }
}) })
...@@ -89,6 +90,7 @@ describe('requirePage', () => { ...@@ -89,6 +90,7 @@ describe('requirePage', () => {
try { try {
await requirePage('/../../test', distDir) await requirePage('/../../test', distDir)
} catch (err) { } catch (err) {
// eslint-disable-next-line jest/no-try-expect
expect(err.code).toBe('ENOENT') expect(err.code).toBe('ENOENT')
} }
}) })
...@@ -98,6 +100,7 @@ describe('requirePage', () => { ...@@ -98,6 +100,7 @@ describe('requirePage', () => {
try { try {
await requirePage('/non-existent', distDir) await requirePage('/non-existent', distDir)
} catch (err) { } catch (err) {
// eslint-disable-next-line jest/no-try-expect
expect(err.code).toBe('ENOENT') expect(err.code).toBe('ENOENT')
} }
}) })
...@@ -107,6 +110,7 @@ describe('requirePage', () => { ...@@ -107,6 +110,7 @@ describe('requirePage', () => {
try { try {
await requirePage('/non-existent-child', distDir) await requirePage('/non-existent-child', distDir)
} catch (err) { } catch (err) {
// eslint-disable-next-line jest/no-try-expect
expect(err.code).toBe('MODULE_NOT_FOUND') expect(err.code).toBe('MODULE_NOT_FOUND')
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment