I get the following error Mirage: Your Ember app tried to GET '/statements', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?
This is while trying to use mirage in a unit test. My acceptance tests work well and seem to load the records just fine. But that is probably because the whole ember app is booted for the acceptance test ?
I'm really sure my config is correct, I have it set up by exporting testConfig:
export function testConfig() {
this.urlPrefix = 'http://0.0.0.0:3000'
this.get('/languages', languages)
this.get('/statements', statements)
Code currently as follows:
//services/fake.js
import Ember from 'ember'
const { Service, A, inject: { service } } = Ember
export default Service.extend({
store: service(),
statements: A(),
loadFakeStatement(){
this.get('statements').addObject(Ember.Object.create({
title: 'Statement 1',
option: 'A'
}))
},
loadRealStatements(){
this.get('store')
.findAll('statement')
.then(statements => {
this.get('statements').addObjects(statements)
})
}
})
// tests/unit/services/fake-test.js
import { moduleFor, test } from 'ember-qunit'
import startMirage from '../../helpers/setup-mirage-for-integration'
moduleFor('service:fake', 'Unit | Service | fake', {
needs: ['model:statement'],
beforeEach() {
startMirage(this.container)
},
afterEach() {
window.server.shutdown()
}
})
test('initializes correctly', function(assert) {
const service = this.subject()
assert.ok(service)
})
test('loads fake data correctly', function(assert) {
const service = this.subject()
assert.equal(service.get('statements.length'), 0, 'statements initially 0')
service.loadFakeStatement()
assert.equal(service.get('statements.length'), 1, 'statements populated by load')
})
test('loads mirage data correctly', function(assert) {
const service = this.subject()
assert.equal(service.get('statements.length'), 0, 'statements initially 0')
service.loadRealStatements()
assert.equal(service.get('statements.length'), 1, 'statements populated by load')
})
Aucun commentaire:
Enregistrer un commentaire