Created
January 3, 2015 18:06
-
-
Save tlvince/551adc53f2e74d75cfe6 to your computer and use it in GitHub Desktop.
This file contains 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
// service.js | |
angular.module('test', []) | |
.service('pouchdb', function($q, $window) { | |
var db = new $window.PouchDB('test'); | |
this.info = function() { | |
return $q.when(db.info.apply(db, arguments)); | |
}; | |
}) | |
.controller('test', function($scope, pouchdb) { | |
pouchdb.info() | |
.then(function(info) { | |
$scope.result = info; | |
}) | |
.catch(function(error) { | |
$scope.result = error; | |
}); | |
}); | |
// service.spec-1.js | |
describe('Failing Q when tests', function() { | |
beforeEach(module('test')); | |
var $rootScope, pouchdb; | |
beforeEach(inject(function(_$rootScope_, pouchdb) { | |
$rootScope = _$rootScope_; | |
pouchdb = pouchdb; | |
})); | |
it('should resolve a promise', function(done) { | |
// FIXME: never resolves | |
pouchdb.info() | |
.then(function(info) { | |
expect(info).toBeDefined(); | |
}) | |
.finally(done); | |
$rootScope.$apply(); | |
}); | |
}); | |
// service.spec-2.js | |
describe('Working Q when tests', function() { | |
var pouchdb; | |
beforeEach(function() { | |
var $injector = angular.injector(['ng', 'test']); | |
var pouchDB = $injector.get('pouchdb'); | |
pouchdb = pouchDB('db'); | |
}); | |
it('should resolve a promise', function(done) { | |
pouchdb.info() | |
.then(function(info) { | |
expect(info).toBeDefined(); | |
}) | |
.finally(done); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment