Skip to content

Commit

Permalink
Check that GitHub tests actually throw, issue eduardoboucas#327
Browse files Browse the repository at this point in the history
  • Loading branch information
travisdowns committed Feb 3, 2020
1 parent c8e339f commit 67fc513
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/unit/lib/GitHub.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,31 @@ describe('GitHub interface', () => {

const githubInstance = await new GitHub(req.params)

let exception = 'thrown'
try {
await githubInstance.readFile(filePath)
exception = 'not thrown'
} catch (err) {
expect(err._smErrorCode).toEqual('GITHUB_READING_FILE')
}

expect(exception).toBe('thrown')
expect(scope.isDone()).toBe(true)
})

test('returns an error if parsing fails for the given file', async () => {
const filePath = 'path/to/file.yml'
const githubInstance = await new GitHub(req.params)

let exception = 'thrown'
try {
await githubInstance.readFile(filePath)
exception = 'not thrown'
} catch (err) {
expect(err._smErrorCode).toEqual('PARSING_ERROR')
expect(err.message).toBeDefined()
}

expect(exception).toBe('thrown')
})

test('reads a YAML file and returns its parsed contents', async () => {
Expand Down Expand Up @@ -290,19 +296,21 @@ describe('GitHub interface', () => {

const githubInstance = await new GitHub(req.params)

let exception = 'thrown'
try {
await githubInstance.writeFile(
options.path,
options.content,
options.branch,
options.commitTitle
)
exception = 'not thrown'
} catch (err) {
expect(err).toEqual({
_smErrorCode: 'GITHUB_WRITING_FILE'
})
}

expect(exception).toBe('thrown')
expect(scope.isDone()).toBe(true)
})
})
Expand Down Expand Up @@ -401,6 +409,7 @@ describe('GitHub interface', () => {

const githubInstance = await new GitHub(req.params)

let exception = 'thrown'
try {
await githubInstance.writeFileAndSendReview(
options.path,
Expand All @@ -409,9 +418,11 @@ describe('GitHub interface', () => {
options.commitTitle,
options.commitBody
)
exception = 'not thrown'
} catch (err) {
expect(err._smErrorCode).toEqual('GITHUB_CREATING_PR')
}
expect(exception).toBe('thrown')
expect(scope.isDone()).toBe(true)
})
})
Expand Down Expand Up @@ -448,11 +459,14 @@ describe('GitHub interface', () => {

const githubInstance = await new GitHub(req.params)

let exception = 'thrown'
try {
await githubInstance.getCurrentUser()
exception = 'not thrown'
} catch (err) {
expect(err._smErrorCode).toEqual('GITHUB_GET_USER')
}
expect(exception).toBe('thrown')
expect(scope.isDone()).toBe(true)
})
})
Expand Down

0 comments on commit 67fc513

Please sign in to comment.