Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge 49c694b into 7467c4e
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Jul 5, 2018
2 parents 7467c4e + 49c694b commit fec0f4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/dom/iswindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
* @returns {Boolean}
*/
export default function isWindow( obj ) {
return Object.prototype.toString.apply( obj ) == '[object Window]';
const stringifiedObject = Object.prototype.toString.apply( obj );

return (
// Returns `true` for the `window` object in browser environments.
stringifiedObject == '[object Window]' ||

// Returns `true` for the `window` object in the Electron environment.
stringifiedObject == '[object global]'
);
}
12 changes: 11 additions & 1 deletion tests/dom/iswindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
import isWindow from '../../src/dom/iswindow';

describe( 'isWindow()', () => {
it( 'detects DOM Window', () => {
it( 'detects DOM Window in browsers', () => {
expect( isWindow( window ) ).to.be.true;
expect( isWindow( {} ) ).to.be.false;
expect( isWindow( null ) ).to.be.false;
expect( isWindow( undefined ) ).to.be.false;
expect( isWindow( new Date() ) ).to.be.false;
expect( isWindow( 42 ) ).to.be.false;
} );

it( 'detects DOM Window in the Electron environment', () => {
const global = {
get [ Symbol.toStringTag ]() {
return 'global';
}
};

expect( isWindow( global ) ).to.be.true;
} );
} );

0 comments on commit fec0f4c

Please sign in to comment.