| 1 |
<!doctype html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>Cross-Realm isPlainObject()</title> |
| 6 |
<script src="../node_modules/chai/chai.js"></script> |
| 7 |
<script src="../node_modules/mocha/mocha.js"></script> |
| 8 |
<script src="../browser/is-plain-object.js"></script> |
| 9 |
<script>mocha.setup('bdd')</script> |
| 10 |
</head> |
| 11 |
<body> |
| 12 |
<div id="mocha"></div> |
| 13 |
<script> |
| 14 |
|
| 15 |
const { isPlainObject } = library; |
| 16 |
|
| 17 |
var expect = chai.expect; |
| 18 |
var iframe,iframeWindow; |
| 19 |
var testArea = document.getElementById('mocha'); |
| 20 |
|
| 21 |
describe('Cross-Realm Browser Tests', function() { |
| 22 |
before( function(done) { |
| 23 |
iframe = document.createElement('iframe'); |
| 24 |
iframe.src = 'browser-iframe.html'; |
| 25 |
iframe.onload = function() { |
| 26 |
iframeWindow = this.contentWindow; |
| 27 |
done(); |
| 28 |
}; |
| 29 |
testArea.appendChild(iframe); |
| 30 |
}); |
| 31 |
|
| 32 |
after( function() { |
| 33 |
testArea.removeChild(iframe); |
| 34 |
}); |
| 35 |
|
| 36 |
describe('without isPlainObject', function() { |
| 37 |
it('should not work with `instanceof`', function() { |
| 38 |
iframeWindow.trues.forEach( function(fixture) { |
| 39 |
expect(fixture).to.not.be.instanceOf(Object); |
| 40 |
}); |
| 41 |
}); |
| 42 |
}); |
| 43 |
|
| 44 |
describe('with isPlainObject', function() { |
| 45 |
it('should return `true` if the object is created by the `Object` constructor.', function() { |
| 46 |
iframeWindow.trues.forEach( function(fixture) { |
| 47 |
expect( isPlainObject(fixture) ).to.be.true; |
| 48 |
}); |
| 49 |
}); |
| 50 |
|
| 51 |
it('should return `false` if the object is not created by the `Object` constructor.', function() { |
| 52 |
iframeWindow.falses.forEach( function(fixture) { |
| 53 |
expect( isPlainObject(fixture) ).to.be.false; |
| 54 |
}); |
| 55 |
}); |
| 56 |
}); |
| 57 |
}); |
| 58 |
|
| 59 |
mocha.run(); |
| 60 |
|
| 61 |
</script> |
| 62 |
</body> |
| 63 |
</html> |