Any Emberenos out there know how to mock a window location? This is for a unit/controller test.
If you'd like to see how the window location's being used, here's the code -
Controller: This is the export action in the Controller, which takes filter inputs 'cycle', 'from', and 'to' and if those inputs contain entries, then it grabs the summary.csv via the api.
export default Ember.Controller.extend({
exportReport: Ember.inject.service(),
i18n: Ember.inject.service(),
queryParams: ['cycle', 'from', 'to'],
nsqip: Ember.inject.controller(),
facility: Ember.computed.alias('nsqip.facility'),
cycle: 0,
from: '',
to: '',
alert: undefined,
export: function() {
var cycle = this.get('cycle');
var from = this.get('from');
var to = this.get('to');
if (cycle === 0 && (!from || !to)){
return;
}
var baseUrl = 'http://localhost:3000/api/summary.csv?cycle=';
window.location.href =
baseUrl + cycle + '&from=' + from + '&to=' + to;
The Unit/Controller test:
var subject, parent;
moduleFor(
'controller:nsqip/reporting',
'Unit | Controller | nsqip/reporting',
{
needs: ['controller:nsqip'],
beforeEach: function() {
subject = this.subject();
parent = subject.get('nsqip');
parent.set('facility', Ember.Object.create({ name: 'test facility' }));
}
}
);
test('it exports summary.csv', function(assert) {
subject.set('cycle', 1);
subject.set('from', '');
subject.set('to', '');
subject.set('baseUrl', 'http://localhost:3000/api/nsqip/v1/reports/summary.csv');
subject.set('window.location.href', 'http://localhost:3000/api/nsqip/v1/reports/summary.csv?cycle=1');
assert.equal(subject.get('cycle'), 1);
subject.send('export');
assert.equal(subject.get(window.location.href).isPresent);
});
The error is
"Property set failed: object in path 'window.location' could not be found or was destroyed."
Aucun commentaire:
Enregistrer un commentaire