Comments (6)
✅ understood and fixed. Thank you.
from miragejs.
It's still basically impossible to truly subclass arrays in JS which is why we chose to go the route of exposing the models as a true array via models
. I usually recommend collection.models.[arrayMethod]
as an escape hatch. That being said we do have filter/sort/slice on there so I'm in favor of adding additional methods.
(One problem we ran into in the past was folks getting confused Collections were actual true arrays, so they'd reasonably pass them into things like lodash array functions only to hit very strange and confusing errors. So that's a concern too.)
What's the use case you ran into? Wanting to do something like [...collection]
?
from miragejs.
The use case is nested components:
The parent model has a has-many relationship, that gets passed into an outer component e.g.,
App code
Context consuming outer component
Outer component template
Inner component JS
@computed('chapters.[]')
get transformedData() {
return this.chapters.toArray().map(...);
}
Test code
this.book = this.server.create('book');
this.chapters = this.server.createList('chapter', 3, { book });
The tests blow up because we have passed books.chapters
down into the child and called toArray()
and map()
on it in the JS file. For app code this works because they are in the store, but test code errors because chapters mirage Collection
doesn't have all the array methods.
from miragejs.
Mmm, I see what's happened. You should not be doing this with Mirage - Mirage models are really intended for the "server" and shouldn't be passed to Ember components.
Give this a read (the second called "Creating Ember Data models on the client with Mirage") and let me know if it makes sense: https://www.ember-cli-mirage.com/docs/testing/integration-and-unit-tests#creating-ember-data-models-on-the-client-with-mirage
from miragejs.
Forgive me for commenting on a closed issue, but I love mirage and i'm using it to generate fixtures for my unit test input but wondering what the best way is to get the raw data (array of objects in this case) without the extra mirage functions tagged on like find
that overwrite the existing array methods.
I've come so far:
mockserver.createList('fileRaw', 10);
const files: FileData[] = Array.from(mockserver.schema.db.fileRaws);
const result = someFn(files);
// assert on result
Is there a better way? I found that Array.from(mockserver.db['fileRaws'])
also works but it is not intuitive to do this as an inexperienced mirage users in my team.
from miragejs.
If you want to get everything in the database try ‘server.db.dump’. This will give you the data in Mirage’s raw db format (camelCase, foreign keys and such). If you want to go through your serializer layer try ‘server.serialize(modelOrCollection).
from miragejs.
Related Issues (20)
- Example using GraphQL and React Native for Testing HOT 2
- How to fix it? my error is: Mirage: Passthrough request for GET /_next/static/development/_devMiddlewareManifest.json
- `timing` setting does not respect `environment: 'test'` without setting `testConfig` HOT 2
- Seeding doesn't load factories HOT 1
- `Response` object is using deprecated `@ember/error` HOT 1
- Can some updates be made so all config elements can be modularized in all environments including development?
- Issues running inside a webpack based NX monorepo React app HOT 3
- `Serializer.normalize()` not called if request body is `FormData`
- How do you include relationships when mixing the JSON API and Rest serializers? HOT 3
- Has anyone managed to get mirage to work with Next.js 13.4? HOT 8
- Argument of type '{ name: string; role: string[]; }' is not assignable to parameter of type 'Partial<ModelInitializ HOT 1
- Change default request handling
- Allow timing to be boolean, default to 'false' due to Pretender handling HOT 6
- Doesn't work with vue3 + fetch + passthrough HOT 2
- Next-pwa throws Failed to execute 'put' on 'Cache': parameter 2 is not of type 'Response' with simple Miraje configuration
- Mirage.js Endpoints Not Found After Navigating and Reloading in Lazy-Loaded Angular App HOT 1
- New Docs Proposal HOT 3
- Firebase `onSnapshot` intercepted
- Composable/extendable traits
- Miragejs not allowing base64 image having lengthy URL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miragejs.