-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
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,11 @@ | ||
import { inTaro } from './inTaro' | ||
|
||
describe('inTaro', () => { | ||
test('表现正常', () => { | ||
expect(inTaro()).toBeFalse() | ||
Object.defineProperty(navigator, 'product', { | ||
value: 'Taro', | ||
}) | ||
expect(inTaro()).toBeTrue() | ||
}) | ||
}) |
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,9 @@ | ||
/** | ||
* 检查是否在 [Taro 3](https://taro.js.org/) 中。 | ||
* | ||
* @returns 返回检查结果 | ||
*/ | ||
export function inTaro(): boolean { | ||
// ref: https://github.com/NervJS/taro/blob/next/packages/taro-runtime/src/bom/navigator.ts#L16 | ||
return typeof navigator !== 'undefined' && navigator.product === 'Taro' | ||
} |
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