A Pen by Andrew Kirchmyer on CodePen.
Created
November 17, 2013 05:06
-
-
Save akirchmyer/7509512 to your computer and use it in GitHub Desktop.
A Pen by Andrew Kirchmyer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = { | |
| model: {} | |
| }; | |
| app.model.getAttributeLater = function (attribute) { | |
| var dfd = $.Deferred(); | |
| return dfd.promise(); | |
| }; | |
| app.model.handleAttribute = function (attribute) { | |
| this.getAttributeLater(attribute) | |
| .done(function (result) { | |
| this.doSomething(result); | |
| }) | |
| .fail(function (result) { | |
| this.youFail(); | |
| }); | |
| }; | |
| app.model.doSomething = function() {}; | |
| app.model.youFail = function() {}; | |
| qunit.test('Test model.handleAttributes', function() { | |
| this.stub(app.model, 'getAttributeLater') | |
| .withArgs('good') | |
| .returns($.Deferred().resolve('gold')) | |
| .withArgs('bad') | |
| .returns($.Deferred().reject()); | |
| this.stub(app.model, 'doSomething'); | |
| this.stub(app.model, 'youFail'); | |
| expect(2); | |
| app.model.handleAttribute('good').done(function(result) { | |
| equal(app.model.doSomething.args[0][0], 'gold', 'do something called with expected param when promise resolved.'); | |
| }); | |
| app.model.handleAttribute('bad').done(function(){ | |
| ok(app.model.youFail.calledOnce, 'youFail called when promise is rejected'); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment