Created
September 13, 2016 00:04
-
-
Save benbabics/dd72a9708393ccb491d453d2a35aaecd to your computer and use it in GitHub Desktop.
Ember Mock Service
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
import Ember from 'ember'; | |
import { moduleFor, test } from 'ember-qunit'; | |
let mockSession = Ember.Service.extend({ | |
isAuthenticated: true, | |
currentUser: Ember.computed('isAuthenticated', function() { | |
return Ember.RSVP.Promise(function(resolve) { | |
resolve( Ember.Object.create({ accounts: [] }) ); | |
}); | |
}) | |
}); | |
moduleFor('route:accounts', 'Unit | Route | accounts', { | |
// Specify the other units that are required for this test. | |
needs: [/*'service:session',*/], | |
beforeEach() { | |
this.container.register( 'service:session', mockSession ); | |
this.container.injection( 'route:accounts', 'session', 'service:session' ); | |
} | |
}); | |
test('it returns a collection of user accounts', function(assert) { | |
let route = this.subject(); | |
assert.deepEqual(route.model()._result, []); | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
session: Ember.inject.service(), | |
model() { | |
return new Ember.RSVP.Promise(resolve => { | |
this.get( 'session.currentUser' ) | |
.then( user => user.get('accounts').then(resolve) ); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment