Add isBrowserTabFocused, fixed is tests

This commit is contained in:
Angelos Chalaris
2018-04-15 19:18:44 +03:00
parent 6056a146e2
commit a4792c9618
6 changed files with 1101 additions and 1104 deletions

View 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
```

View File

@ -121,6 +121,7 @@ isAnagram:string,regexp
isArrayLike:type,array
isBoolean:type
isBrowser:utility,browser
isBrowserTabFocused:browser
isDivisible:math
isEmpty:type,array,object,string
isEven:math

View File

@ -14,11 +14,11 @@ test('Testing is', (t) => {
t.true(is(Set, new Set()), `Works for sets`);
t.true(is(WeakMap, new WeakMap()), `Works for weak maps`);
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.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.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(Function, () => null), `Works for functions`);
//t.deepEqual(is(args..), 'Expected');

View File

@ -0,0 +1,2 @@
const isBrowserTabFocused = () => !document.hidden;
module.exports = isBrowserTabFocused;

View 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();
});

File diff suppressed because it is too large Load Diff