Skip to content

Commit

Permalink
test(x): 补充 setNavigationBarColor 相关测试
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto-J committed May 11, 2024
1 parent e4db928 commit a752563
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const API_SET_NAVIGATION_BAR_COLOR = '1'
const SetNavigationBarColorOptions = {}
const SetNavigationBarColorProtocol = {}

const updateStyle = jest.fn()
jest.mock('@dcloudio/uni-core', () => {
return {
getCurrentPage: jest.fn(() => {
return {
$nativePage: {
updateStyle,
},
}
}),
}
})

jest.mock('@dcloudio/uni-api', () => {
const mockdefineAsyncApi = jest.fn((name, fn, protocol, options) => {
return [name, fn, protocol, options]
})

return {
__esModule: true,
API_SET_NAVIGATION_BAR_COLOR: API_SET_NAVIGATION_BAR_COLOR,
SetNavigationBarColorOptions: SetNavigationBarColorOptions,
SetNavigationBarColorProtocol: SetNavigationBarColorProtocol,
defineAsyncApi: mockdefineAsyncApi,
}
})

import { setNavigationBarColor as setNavigationBarColorReturn } from './setNavigationBarColor'

describe('setNavigationBarColor', () => {
it('should setNavigationBarColor', async () => {
expect(setNavigationBarColorReturn).toEqual([
API_SET_NAVIGATION_BAR_COLOR,
expect.any(Function),
SetNavigationBarColorProtocol,
SetNavigationBarColorOptions,
])

const fn = setNavigationBarColorReturn[1]
expect(typeof fn).toBe('function')

// mock call
const options = { frontColor: '#000000', backgroundColor: '#ff0000' }
fn(options, { resolve: jest.fn(), reject: jest.fn() })

expect(updateStyle).toHaveBeenCalledTimes(1)

const val1 = new Map<string, any | null>([
[
'navigationBarTextStyle',
options.frontColor == '#000000' ? 'black' : 'white',
],
['navigationBarBackgroundColor', options.backgroundColor],
])
expect(updateStyle).toHaveBeenCalledWith(val1)
})
})

0 comments on commit a752563

Please sign in to comment.