Skip to content

Commit

Permalink
Enable jest/no-try-expect (vercel#13124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored and chibicode committed May 21, 2020
1 parent 247cb0e commit e0cc902
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down
2 changes: 2 additions & 0 deletions test/integration/create-next-app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
}
})
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 6 additions & 14 deletions test/isolated/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions test/isolated/require-page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
})
Expand Down Expand Up @@ -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')
}
})
Expand All @@ -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')
}
})
Expand All @@ -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')
}
})
Expand Down

0 comments on commit e0cc902

Please sign in to comment.