I have spent the last several hours trying to get a stable test environment for working with an app that uses Ember Data. I had all the tests passing with FixtureAdapter, which of course is not viable long term. I have tried to move to Pretender and to ember-cli-mirage and they both have issues. In many cases I get errors about findAll returning undefined rather than an array. I have one simple case passing with mirage, but other cases just as simple fail, as do my integration tests.
I am looking for a working example that coves the following:
- How to configure mirage or pretender directly to provide test data to an acceptance test of an app using RESTAdapter.
- How to use mirage or pretender for model unit tests (cases where multiple model objects are required for a test function (or advise that this belongs in another kind of test, and if so how to set that up).
I have mirage working with fixtures in development. My tests currently are just looking for empty responses to the various get calls as a first step, so I should not need to be using factories yet.
An example app with ember-data + pretender exists at: GitHub - stefanpenner/ember-jobs maybe you can use that as a reference.
Thank you. I will check it out.
Tests are working now. There were some subtile differences in your setup, and pretender 0.1.0 was being used for some reason. Thanks again.
I’m the author of mirage and am really committed to it being a useful solution, especially for people just starting out with ember + testing. I’ve found hand-written Pretender scripts quickly become difficult to maintain, which is how mirage originated.
I’d be happy to pair with you to get mirage working, or you can open an issue on the repo.
@samselikoff I am also trying to get started with ember cli mirage. Thanks for the demo at ember conf.
Unfortunately for me I have fairly advanced app already built with very few tests so need to figure out how back port a bunch of test code to match current implementation.
I would be also interested in seeing a fleshed out example that shows some of the finer points of how to setup tests with mirage.
Something that demonstrates more than just the basics, seeing adapters, services, utilities and aspects of an advanced ember cli project with full test coverage.
Do you have such a thing published anywhere? If you would like to pair on this sometime let me know. Would love to help out and see something built out.
What would be really helpful to new comers, I think, is a fully built suite of tests to guide an example app from zero implementation code to complete app. It could be setup as a series of steps in a git repo that can guide someone along the way. If you would like to collaborate on something like this let me know. I think when done could be a good asset to demonstrate the features of mirage and also be useful training material for people trying to learn ember and how to build a whole app from start to finish.
Think something like https://github.com/substack/stream-adventure but with ember and mirage.
That’s a wonderful idea. I’m in the process of building the orm layer which will pave the way for serializers + easy relationships. Currently, you need to manage related ids yourself, either in fixtures or factories.
Once this layer is done, it will be much more practical to e.g. add a JSON API serializer layer to Mirage, so you don’t have to write this yourself. The goal is essentially to move us away from hand-written Pretender scripts for each project, as those get pretty nasty to maintain, and move towards something that lets share work + write less code in this area.
After this step I’m planning on making a docs site, which would be a great place for a screencast walking through setting up your app with Mirage. Until then I’d be happy to pair with you on your specific project. If your API falls far outside of AMS conventions it should still be possible to mock it with Mirage, though you’ll probably be using the function handler to do a lot of your work.