Skip to content

Instantly share code, notes, and snippets.

@tlvince
Created January 3, 2015 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlvince/551adc53f2e74d75cfe6 to your computer and use it in GitHub Desktop.
Save tlvince/551adc53f2e74d75cfe6 to your computer and use it in GitHub Desktop.
// 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