diff options
Diffstat (limited to 'test/scenario/FutureSpec.js')
| -rw-r--r-- | test/scenario/FutureSpec.js | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/test/scenario/FutureSpec.js b/test/scenario/FutureSpec.js index ae475779..1e6af7a1 100644 --- a/test/scenario/FutureSpec.js +++ b/test/scenario/FutureSpec.js @@ -1,13 +1,14 @@ describe('angular.scenario.Future', function() { var future; - it('should set the name and behavior', function() { + it('should set the sane defaults', function() { var behavior = function() {}; var future = new angular.scenario.Future('test name', behavior); expect(future.name).toEqual('test name'); expect(future.behavior).toEqual(behavior); expect(future.value).toBeUndefined(); expect(future.fulfilled).toBeFalsy(); + expect(future.parser).toEqual(angular.identity); }); it('should be fulfilled after execution and done callback', function() { @@ -35,4 +36,39 @@ describe('angular.scenario.Future', function() { future.execute(angular.noop); expect(future.value).toEqual(10); }); + + it('should parse json with fromJson', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, "{test: 'foo'}"); + }); + future.fromJson().execute(angular.noop); + expect(future.value).toEqual({test: 'foo'}); + }); + + it('should convert to json with toJson', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, {test: 'foo'}); + }); + future.toJson().execute(angular.noop); + expect(future.value).toEqual('{"test":"foo"}'); + }); + + it('should convert with custom parser', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, 'foo'); + }); + future.parsedWith(function(value) { + return value.toUpperCase(); + }).execute(angular.noop); + expect(future.value).toEqual('FOO'); + }); + + it('should pass error if parser fails', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, '{'); + }); + future.fromJson().execute(function(error, result) { + expect(error).toBeDefined(); + }); + }); }); |
