-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(x): 补充 setNavigationBarColor 相关测试
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/uni-app-plus/src/x/api/navigationBar/setNavigationBarColor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |