Skip to content

Commit

Permalink
test(x): 测试完善 setNavigationBarTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto-J committed May 11, 2024
1 parent 3405f9a commit 234e9ea
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const API_SET_NAVIGATION_BAR_TITLE = '1'
const SetNavigationBarTitleProtocol = {}

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_TITLE,
SetNavigationBarTitleProtocol,
defineAsyncApi: mockdefineAsyncApi,
}
})

import { setNavigationBarTitle as setNavigationBarTitleReturn } from './setNavigationBarTitle'

describe('test:setNavigationBarTitle', () => {
it('should setNavigationBarTitle', async () => {
const [name, fn, protocol, options] = setNavigationBarTitleReturn as any

expect(typeof name).toBe('string')
expect(typeof fn).toBe('function')
expect(typeof protocol).toBe('object')
expect(typeof options).toBe('undefined')

const mockOptions = {
title: 'test',
}

const resolve = jest.fn()

fn(mockOptions, { resolve, reject: jest.fn() })
expect(updateStyle).toHaveBeenCalledTimes(1)
expect(updateStyle).toHaveBeenCalledWith(
new Map([['navigationBarTitleText', mockOptions.title]])
)
expect(resolve).toHaveBeenCalledTimes(1)
})
})

0 comments on commit 234e9ea

Please sign in to comment.