【发布时间】:2016-12-13 12:30:48
【问题描述】:
我有一个 Ember 插件,它应该处理返回一些数据的请求。主应用程序需要使用此插件,以便从 mirage 中检索检索此数据的请求。在未来的某个时候,这需要在实时环境中禁用(但暂时不是)
我的问题是mirage 目录(及其子目录,例如factories、fixtures、models、routes 等)应该位于插件中的哪个位置。它应该在项目根目录中还是其他位置,例如在app 或addon 子目录中?
我已经跑了:
ember install ember-cli-mirage
在\tests\dummy\mirage中创建一些文件
在此目录中创建文件似乎不起作用:
/tests/dummy/fixtures/mydata.js
export default [{
"title": "Some data here"
}]
/tests/dummy/routes/mydata.js
class MyDataRoutes {
constructor(routerFnc, route, db) {
routerFnc(route + '/', ({db}) => {
return db.mydata;
});
}
}
导出默认 MyDataRoutes;
/tests/mirage/config.js:
export default function() {
// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server
this.namespace = 'api'; // make this `api`, for example, if your API is namespaced
this.timing = 100; // delay for each request, automatically set to 0 during testing
new MyDataRoutes(this.get, '/content/mydata', this.db);
}
【问题讨论】:
标签: node.js ember.js npm ember-cli