Skip to content

Commit

Permalink
feat(utils): inWechat 更名为 inWechatWebView
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jul 23, 2020
1 parent 5e33e2c commit 1d341e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/utils/inWechat.test.ts → src/utils/inWechatWebView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ Object.defineProperty(window.navigator, 'userAgent', {
writable: true,
})

describe('inWechat', () => {
describe('inWechatWebView', () => {
afterEach(() => {
jest.resetModules()
})

test('不在微信内置浏览器中', async () => {
const { inWechat } = await import('./inWechat')
const { inWechatWebView } = await import('./inWechatWebView')
// @ts-ignore
window.navigator.userAgent = 'x'
expect(inWechat()).toBeFalse()
expect(inWechatWebView()).toBeFalse()
})

test('在微信内置浏览器中', async () => {
const { inWechat } = await import('./inWechat')
const { inWechatWebView } = await import('./inWechatWebView')
// @ts-ignore
window.navigator.userAgent = 'xx MicroMessenger yy'
expect(inWechat()).toBeTrue()
expect(inWechatWebView()).toBeTrue()
})
})
4 changes: 2 additions & 2 deletions src/utils/inWechat.ts → src/utils/inWechatWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ let yes!: boolean
* @returns 返回检查结果
* @example
* ```typescript
* if (inWechat()) {
* if (inWechatWebView()) {
* console.log('你在微信内置浏览器中')
* }
* ```
*/
export function inWechat(): boolean {
export function inWechatWebView(): boolean {
if (yes == null) {
yes =
inBrowser() &&
Expand Down

0 comments on commit 1d341e4

Please sign in to comment.