Add isBrowserTabFocused, fixed is tests
This commit is contained in:
13
snippets/isBrowserTabFocused.md
Normal file
13
snippets/isBrowserTabFocused.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
### isBrowserTabFocused
|
||||||
|
|
||||||
|
Returns `true` if the browser tab of the page is focused, `false` otherwise.
|
||||||
|
|
||||||
|
Use the `Document.hidden` property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isBrowserTabFocused = () => !document.hidden;
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
isBrowserTabFocused(); // true
|
||||||
|
```
|
||||||
@ -121,6 +121,7 @@ isAnagram:string,regexp
|
|||||||
isArrayLike:type,array
|
isArrayLike:type,array
|
||||||
isBoolean:type
|
isBoolean:type
|
||||||
isBrowser:utility,browser
|
isBrowser:utility,browser
|
||||||
|
isBrowserTabFocused:browser
|
||||||
isDivisible:math
|
isDivisible:math
|
||||||
isEmpty:type,array,object,string
|
isEmpty:type,array,object,string
|
||||||
isEven:math
|
isEven:math
|
||||||
|
|||||||
@ -14,11 +14,11 @@ test('Testing is', (t) => {
|
|||||||
t.true(is(Set, new Set()), `Works for sets`);
|
t.true(is(Set, new Set()), `Works for sets`);
|
||||||
t.true(is(WeakMap, new WeakMap()), `Works for weak maps`);
|
t.true(is(WeakMap, new WeakMap()), `Works for weak maps`);
|
||||||
t.true(is(WeakSet, new WeakSet()), `Works for weak sets`);
|
t.true(is(WeakSet, new WeakSet()), `Works for weak sets`);
|
||||||
t.false(is(String, ''), `Works for strings - returns false for primitive`);
|
t.true(is(String, ''), `Works for strings - returns true for primitive`);
|
||||||
t.true(is(String, new String('')), `Works for strings - returns true when using constructor`);
|
t.true(is(String, new String('')), `Works for strings - returns true when using constructor`);
|
||||||
t.false(is(Number, 1), `Works for numbers - returns false for primitive`);
|
t.true(is(Number, 1), `Works for numbers - returns true for primitive`);
|
||||||
t.true(is(Number, new Number('10')), `Works for numbers - returns true when using constructor`);
|
t.true(is(Number, new Number('10')), `Works for numbers - returns true when using constructor`);
|
||||||
t.false(is(Boolean, false), `Works for booleans - returns false for primitive`);
|
t.true(is(Boolean, false), `Works for booleans - returns true for primitive`);
|
||||||
t.true(is(Boolean, new Boolean(false)), `Works for booleans - returns true when using constructor`);
|
t.true(is(Boolean, new Boolean(false)), `Works for booleans - returns true when using constructor`);
|
||||||
t.true(is(Function, () => null), `Works for functions`);
|
t.true(is(Function, () => null), `Works for functions`);
|
||||||
//t.deepEqual(is(args..), 'Expected');
|
//t.deepEqual(is(args..), 'Expected');
|
||||||
|
|||||||
2
test/isBrowserTabFocused/isBrowserTabFocused.js
Normal file
2
test/isBrowserTabFocused/isBrowserTabFocused.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
const isBrowserTabFocused = () => !document.hidden;
|
||||||
|
module.exports = isBrowserTabFocused;
|
||||||
13
test/isBrowserTabFocused/isBrowserTabFocused.test.js
Normal file
13
test/isBrowserTabFocused/isBrowserTabFocused.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const isBrowserTabFocused = require('./isBrowserTabFocused.js');
|
||||||
|
|
||||||
|
test('Testing isBrowserTabFocused', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof isBrowserTabFocused === 'function', 'isBrowserTabFocused is a Function');
|
||||||
|
//t.deepEqual(isBrowserTabFocused(args..), 'Expected');
|
||||||
|
//t.equal(isBrowserTabFocused(args..), 'Expected');
|
||||||
|
//t.false(isBrowserTabFocused(args..), 'Expected');
|
||||||
|
//t.throws(isBrowserTabFocused(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
2170
test/testlog
2170
test/testlog
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user