|
| 1 | +function runWithThis(obj, fn) { |
| 2 | + fn.call(obj); |
| 3 | +} |
| 4 | + |
| 5 | +it("should bind this context on require callback", function(done) { |
| 6 | + require("./file"); |
| 7 | + runWithThis({ok: true}, function() { |
| 8 | + require([], function() { |
| 9 | + try { |
| 10 | + require("./file").should.be.eql("file"); |
| 11 | + this.should.be.eql({ok: true}); |
| 12 | + done(); |
| 13 | + } catch(e) { done(e); } |
| 14 | + }.bind(this)); |
| 15 | + }) |
| 16 | +}); |
| 17 | + |
| 18 | +it("should bind this context on require callback (loaded)", function(done) { |
| 19 | + runWithThis({ok: true}, function() { |
| 20 | + require(["./load.js"], function(load) { |
| 21 | + try { |
| 22 | + require("./file").should.be.eql("file"); |
| 23 | + load.should.be.eql("load"); |
| 24 | + this.should.be.eql({ok: true}); |
| 25 | + done(); |
| 26 | + } catch(e) { done(e); } |
| 27 | + }.bind(this)); |
| 28 | + }) |
| 29 | +}); |
| 30 | + |
| 31 | +it("should bind this context on require.ensure callback", function(done) { |
| 32 | + runWithThis({ok: true}, function() { |
| 33 | + require.ensure([], function(require) { |
| 34 | + try { |
| 35 | + require("./file").should.be.eql("file"); |
| 36 | + this.should.be.eql({ok: true}); |
| 37 | + done(); |
| 38 | + } catch(e) { done(e); } |
| 39 | + }.bind(this)); |
| 40 | + }) |
| 41 | +}); |
| 42 | + |
| 43 | +it("should bind this context on require.ensure callback (loaded)", function(done) { |
| 44 | + runWithThis({ok: true}, function() { |
| 45 | + require.ensure(["./load.js"], function(require) { |
| 46 | + try { |
| 47 | + require("./file").should.be.eql("file"); |
| 48 | + this.should.be.eql({ok: true}); |
| 49 | + done(); |
| 50 | + } catch(e) { done(e); } |
| 51 | + }.bind(this)); |
| 52 | + }) |
| 53 | +}); |
0 commit comments