|
| 1 | +<html> |
| 2 | +<head> |
| 3 | + <!-- https://mochajs.org/#running-mocha-in-the-browser --> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>Mocha Tests</title> |
| 6 | + <link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" /> |
| 7 | + <script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script> |
| 8 | + <script src="https://cdn.rawgit.com/chaijs/chai/3.5.0/chai.js"></script> |
| 9 | + <script src="https://cdn.rawgit.com/cujojs/curl/0.8.13/dist/curl/curl.js"></script> |
| 10 | + <script src="https://cdn.rawgit.com/taylorhakes/promise-polyfill/6.0.2/promise.js"></script> |
| 11 | +</head> |
| 12 | +<body> |
| 13 | + <div id="mocha"></div> |
| 14 | + |
| 15 | + <div id="css-target"></div> |
| 16 | + |
| 17 | + <script type="text/javascript"> |
| 18 | + curl.config({ baseUrl: "../lib" }); |
| 19 | + curl(['basic-loader-amd'], function (load) { |
| 20 | + |
| 21 | + mocha.ui('bdd'); |
| 22 | + expect = chai.expect; |
| 23 | + |
| 24 | + function getProp(elem, prop) { |
| 25 | + return window.getComputedStyle(elem, null).getPropertyValue(prop); |
| 26 | + } |
| 27 | + |
| 28 | + describe('basic-loader', function () { |
| 29 | + |
| 30 | + it('should load javascript files', function (done) { |
| 31 | + expect(window.foo).to.be.undefined; |
| 32 | + load.js('foo.js').then(function () { |
| 33 | + expect(window.foo).to.be.true; |
| 34 | + done(); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should raise a promise error for non-existent javascript files', function (done) { |
| 39 | + load.js('foo-missing.js').catch(function () { |
| 40 | + done(); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should load image files', function (done) { |
| 45 | + expect(document.getElementsByTagName('IMG').length).to.equal(0); // empty breaks phantom |
| 46 | + load.img('bar.png').then(function () { |
| 47 | + expect(document.getElementsByTagName('IMG')).to.have.length(1); |
| 48 | + done(); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should raise a promise error for non-existent image files', function (done) { |
| 53 | + load.img('bar-missing.png').catch(function () { |
| 54 | + done(); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should load css files', function (done) { |
| 59 | + var target = document.getElementById('css-target'); |
| 60 | + expect(getProp(target, 'color')).to.equal('rgb(0, 0, 0)'); // phantom is terribly picky about props |
| 61 | + load.css('baz.css').then(function () { |
| 62 | + expect(getProp(target, 'color')).to.equal('rgb(255, 0, 0)'); |
| 63 | + done(); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should raise a promise error for non-existent css files', function (done) { |
| 68 | + load.img('baz-missing.css').catch(function () { |
| 69 | + done(); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + }); |
| 74 | + |
| 75 | + mocha.run(); |
| 76 | + }); |
| 77 | + </script> |
| 78 | +</body> |
| 79 | +</html> |
0 commit comments