forked from mirrors/probot
refactor: spy on `github.repos.getContents` function without removing function properties
This commit is contained in:
parent
20e5914b3b
commit
5567e97b32
|
@ -103,7 +103,7 @@ describe('Context', () => {
|
|||
})
|
||||
|
||||
it('gets a valid configuration', async () => {
|
||||
github.repos.getContents = jest.fn().mockReturnValue(Promise.resolve(readConfig('basic.yml')))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(Promise.resolve(readConfig('basic.yml')))
|
||||
const config = await context.config('test-file.yml')
|
||||
|
||||
expect(github.repos.getContents).toHaveBeenCalledWith({
|
||||
|
@ -126,7 +126,7 @@ describe('Context', () => {
|
|||
status: 'Not Found'
|
||||
}
|
||||
|
||||
github.repos.getContents = jest.fn().mockReturnValue(Promise.reject(error))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(Promise.reject(error))
|
||||
|
||||
expect(await context.config('test-file.yml')).toBe(null)
|
||||
})
|
||||
|
@ -139,7 +139,7 @@ describe('Context', () => {
|
|||
status: 'Not Found'
|
||||
}
|
||||
|
||||
github.repos.getContents = jest.fn().mockReturnValue(Promise.reject(error))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(Promise.reject(error))
|
||||
const defaultConfig = {
|
||||
bar: 7,
|
||||
baz: 11,
|
||||
|
@ -150,7 +150,7 @@ describe('Context', () => {
|
|||
})
|
||||
|
||||
it('throws when the configuration file is malformed', async () => {
|
||||
github.repos.getContents = jest.fn().mockReturnValue(Promise.resolve(readConfig('malformed.yml')))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(Promise.resolve(readConfig('malformed.yml')))
|
||||
|
||||
let e
|
||||
let contents
|
||||
|
@ -166,7 +166,7 @@ describe('Context', () => {
|
|||
})
|
||||
|
||||
it('throws when loading unsafe yaml', async () => {
|
||||
github.repos.getContents = jest.fn().mockReturnValue(readConfig('evil.yml'))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(readConfig('evil.yml'))
|
||||
|
||||
let e
|
||||
let config
|
||||
|
@ -182,7 +182,7 @@ describe('Context', () => {
|
|||
})
|
||||
|
||||
it('returns an empty object when the file is empty', async () => {
|
||||
github.repos.getContents = jest.fn().mockReturnValue(readConfig('empty.yml'))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(readConfig('empty.yml'))
|
||||
|
||||
const contents = await context.config('test-file.yml')
|
||||
|
||||
|
@ -190,7 +190,7 @@ describe('Context', () => {
|
|||
})
|
||||
|
||||
it('overwrites default config settings', async () => {
|
||||
github.repos.getContents = jest.fn().mockReturnValue(Promise.resolve(readConfig('basic.yml')))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(Promise.resolve(readConfig('basic.yml')))
|
||||
const config = await context.config('test-file.yml', { foo: 10 })
|
||||
|
||||
expect(github.repos.getContents).toHaveBeenCalledWith({
|
||||
|
@ -206,7 +206,7 @@ describe('Context', () => {
|
|||
})
|
||||
|
||||
it('uses default settings to fill in missing options', async () => {
|
||||
github.repos.getContents = jest.fn().mockReturnValue(Promise.resolve(readConfig('missing.yml')))
|
||||
jest.spyOn(github.repos, 'getContents').mockReturnValue(Promise.resolve(readConfig('missing.yml')))
|
||||
const config = await context.config('test-file.yml', { bar: 7 })
|
||||
|
||||
expect(github.repos.getContents).toHaveBeenCalledWith({
|
||||
|
|
Loading…
Reference in New Issue