Skip to content

Loading…

Add Require.js errback to the Squire require method #24

Merged
merged 2 commits into from

2 participants

@jump

For reference: errbacks

@iammerrick iammerrick merged commit c646b12 into iammerrick:master
@iammerrick
Owner

Thank you. :-)

@jump

No problem. Thank you for Squire!

@jump jump deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 26, 2013
  1. Add Require.js errback to the Squire require method.

    Adam Pearse committed
  2. Update docs with errback change.

    Adam Pearse committed
Showing with 19 additions and 3 deletions.
  1. +4 −1 README.md
  2. +2 −2 src/Squire.js
  3. +13 −0 test/tests/SquireTests.js
View
5 README.md
@@ -24,12 +24,15 @@ define(['Squire'], function(Squire) {
var injector = new Squire('other-requirejs-context');
```
-### require(Array dependencies, Function callback)
+### require(Array dependencies, Function callback, Function errback)
```javascript
var injector = new Squire();
injector.require(['utilities/Calculator'], function(Calculator) {
// Calculator has been loaded.
+},
+function(err) {
+ // Calculator threw an error loading.
});
```
View
4 src/Squire.js
@@ -141,7 +141,7 @@ define(function() {
return this;
};
- Squire.prototype.require = function(dependencies, callback) {
+ Squire.prototype.require = function(dependencies, callback, errback) {
var magicModuleName = 'mocks';
var self = this;
var path, magicModuleLocation;
@@ -177,7 +177,7 @@ define(function() {
each(self.requiredCallbacks, function(cb) {
cb.call(null, dependencies, args);
});
- });
+ }, errback);
};
Squire.prototype.clean = function(mock) {
View
13 test/tests/SquireTests.js
@@ -110,6 +110,19 @@ define(['Squire'], function(Squire) {
squire.require(['mocks/Shirt'], function (shirt) {});
});
+
+ it('should call an errback when a dependency throws an error', function(done) {
+ var squire = new Squire();
+ squire
+ .mock('mocks/Shirt', function() {
+ throw new Error('fashion disaster');
+ })
+ .require(['mocks/Shirt'], chai.assert.fail, function(err) {
+ err.requireModules.should.deep.equal(['mocks/Shirt']);
+ err.message.should.equal('fashion disaster');
+ done();
+ });
+ });
});
describe('store', function(){
Something went wrong with that request. Please try again.