ember-cli-mirage | An Ember Addon to easily add Mirage JS to your Ember app | Addon library
kandi X-RAY | ember-cli-mirage Summary
kandi X-RAY | ember-cli-mirage Summary
This library is developed and maintained by EmberMap. We have a Mirage tips and tricks video series if you're looking to learn how to get the most out of Mirage.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ember-cli-mirage
ember-cli-mirage Key Features
ember-cli-mirage Examples and Code Snippets
ember install ember-cli-mirage
ENV['ember-cli-mirage'] = {
discoverEmberDataModels: true
};
ember install ember-cli-mirage
export default function() {
this.namespace = '/api';
this.get('/users', function() {
return {
// list of users
};
});
}
ember generate
Community Discussions
Trending Discussions on ember-cli-mirage
QUESTION
I've got following models:
...ANSWER
Answered 2019-Nov-14 at 16:08Glad you found include
! The idea there is that whether associations are included or not can depend on the request. For example, with JSON:API a lot of apps will use query param includes to specify inclusion from the client-side. Other apps will have their servers send over default server-side includes, and that's what the include
key is used for.
Also note that include
can be a function, if you want more dynamic behavior. You can check out the docs for some examples.
Last point – your get
handlers really should be returning what's already in Mirage's database, rather than creating new resources then returning them. This way your app will behave more similar to how it will in production.
So instead of
QUESTION
I am quite new to ember.js. I have been working on the tutorial and having issue with generating adapter application.
When i run the command ember generate adapter application i can see message saying installing adapter and installing adapter-test but no file is getting generated in the folder structure .
Package.json
...ANSWER
Answered 2019-Jul-23 at 07:48Ola @Divakar, thanks for your question! And Welcome to Ember
Looking at your question it seems like it could be related to an issue that we had recently in ember-data where the generators were broken. I think they were fixed in ember-data@3.11.1
but from your package.json it would seem that you have ember-data@3.11.0
If you want to update ember-data and see if the issue is still there you can run the following:
QUESTION
I have declared a properties in a Mirage factory as below and using Dependent attributes as found in the docs.
...ANSWER
Answered 2019-Jul-09 at 07:59Mirage factory are meant to generate testing data:
Factories are classes that help you organize your data-creation logic, making it easier to define different server states during development or within tests.
The factory is only run once by server.create('foo')
or server.createList('foo', 10)
to create initial data for the records. This helps you to avoid code duplication in tests and scenarios. But it's not a model representing that record.
Actually Mirage does not support something like computed properties out of the box. But you could achieve it by customizing the serializer used. Overriding the serialize
method should do the trick:
QUESTION
I am working on a new Ember.js project and using ember-cli-mirage to stub out my requests. The project is going to use ember-simple-auth
and Auth0 for user authentication. I began implementing them in my project, but I'm getting a weird error in the console when I try to sign up with my Google account using the Auth0 login modal:
ANSWER
Answered 2019-May-27 at 17:30Ember CLI Mirage intercepts all ajax (XMLHttpRequest
) and fetch
requests by default. You have to whitelist the requests that should be passed through by using server.passthrough()
method. (this
is server
instance in mirage/config.js
.) You could use relative and absolute URLs with server.passthrough
as well as with all route handlers. So server.passthrough('https://(my auth0 domain).auth0.com/userinfo')
should fix your issue.
QUESTION
A newbie to ember, I am trying to simulate the API server using ember-cli-mirage. I am creating a request from account.js
through store
but the response is not something I expect.
ANSWER
Answered 2019-May-22 at 16:38You're logging response
which is actually the return value of store.findAll
, rather than the HTTP response from Mirage.
store.findAll
wraps up the HTTP request/response logic, and actually responds with an instance of an Ember Data model, or an array of models. In your case since you called findAll
, the response is an array of Ember Data models.
If you want to see the details of Mirage's response, check your console for something like Mirage: 200 OK for GET /accounts
. You should be able to expand that to see the details of the request and response that Mirage handled.
QUESTION
Having recently migrated Ember CLI from 2.15.0 to 3.7.0, the acceptance tests have regressed heavily. Having run the qunit codemod, the following issue seems to persist: UnrecognizedURLError: /tests
.
I have produced a minimum reproduction of the issue via the following acceptance test:
...ANSWER
Answered 2019-Mar-28 at 23:10As @jelhan points to in the comment above, the issue here is missing test
environment settings within the environment.js
configuration.
To fix the UnrecognizedURLError
, adding ENV.locationType = 'none'
satisfies the requirements of testem.
I also replaced the other environment variables found in the linked block.
My test environment configuration now looks like this:
QUESTION
I am on halfway of implementing JSON API structure (with underscore attributes).
Actual state for development environment is:
I use the Active Model Adapter structure for requesting to the backend for resources and backend response me with JSON API structure.
In Application Serializer I am using JSONAPISerializer
. I override methods:
ANSWER
Answered 2019-Mar-10 at 19:05Let's try to focus a single relationship, since there's a lot going on in the question you've posted. We'll look at second-resource
.
It looks like Mirage is sending back second_resource_ids
under the attributes
key of the first_resource
primary data in the JSON:API payload. That tells me Mirage thinks second_resource_ids
is an attribute of first_resource
, when in fact it's a relationship.
Assuming your Models & Relationships are setup correctly, you need to tweak the way you're creating data in Mirage.
If you take a look at the Associations section of the Defining Routes guide, you'll see this message:
Mirage's database uses camelCase for all model attributes, including foreign keys (e.g. authorId in the example above)
Right now, you're doing this:
QUESTION
I need to override this method: normalize(payload, modelName)
in ember-cli-mirage addon and serializer-registry file
https://github.com/samselikoff/ember-cli-mirage/blob/master/addon/serializer-registry.js#L21
I have no idea where to put file to override it in my ember project.
...ANSWER
Answered 2019-Mar-07 at 20:07Do you need to override it for all serializers or just one?
If all, you could so something like this on the application serializer:
QUESTION
I'm trying to get working my project based on EmberJS on another computer.
I've cloned the repo, and when I'm trying to run npm install
it hangs on extracting Faker package.
extract:faker: verb gentlyRm don't care about contents; nuking C:\Users\Babanov.Viktor\PhpstormProjects\IdeaPlannerFront\node_modules.staging\faker-c7ff04ca\node_modules
I tried to wait for a couple of hours, and nothing changed. Removing of the .stage
directory didn't give any effect.
Here are my package.json
contents:
ANSWER
Answered 2017-Sep-06 at 10:47ember-cli
is having another dependency calledember-cli-mirage
which is dependant onfaker
.- On previous machine, check what versions are there for
node, npm, ember-cli, bower and phantomjs-prebuilt
. Either you can use same versions. Or try clearing cache and updating only npm using:
QUESTION
I have some experience with Ember.js, and am now going through creating a new project, with Mirage to stub the data for now.
I'm going through the Ember.js Tutorial step by step but keep getting this error when querying for records:
Encountered a resource object with an undefined type (resolved resource using DS.JSONAPISerializer)
I do realize that a similar question has been asked, but it did not include the Mirage addon, and I also went through all of the techniques answered in that question.
mirage/config.js
ANSWER
Answered 2018-Oct-30 at 17:09I think the problem you are facing is due to the fact that your mirage data isn't formatted as-per JSON-API specifications.
mirage/config.js
=>
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ember-cli-mirage
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page