Ember CLI Mirage is an Ember CLI addon that provides a client-side server, enabling developers to build, test, and prototype Ember applications without a real backend. It intercepts HTTP requests made by an Ember app and responds with mocked data, making it invaluable for rapid development, consistent testing, and demonstrating features in isolation. The current stable version is 3.0.4, with frequent patch and minor releases, reflecting active maintenance and responsiveness to the Ember ecosystem. A key differentiator is its deep integration with Ember CLI and Ember Data, allowing for auto-discovery of models and simplified setup. It leverages the standalone MirageJS library for its core mocking capabilities, providing a robust and flexible API for defining API endpoints, factories, and serializers.
npm install ember-cli-mirageVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install `ember-cli-mirage`, define basic mock API routes in `mirage/config.js`, and integrate `setupMirage` into an Ember QUnit test to provide mock data.
Run `npm install miragejs` (or `yarn add miragejs`) in your project root after upgrading to `ember-cli-mirage@3.x`.
Update your `mirage/config.js` to use `import { createServer } from 'miragejs';` and pass your config to it, instead of instantiating `Server` directly from `ember-cli-mirage`.Replace `import { Response } from 'ember-cli-mirage/response';` (and similar re-exports) with `import { Response } from 'miragejs';`.Ensure your project meets the minimum requirements: upgrade Ember.js to 3.28 or higher and Node.js to 16 or higher. Run `npx ember-cli-update` for assistance.
Always include `setupMirage(hooks);` within your QUnit or Mocha `module()` setup function for tests that interact with Mirage.
Run `npm install miragejs` or `yarn add miragejs` to add the core library to your project's dependencies.
Change your `mirage/config.js` to import `createServer` from `miragejs` and call it with your config function: `import { createServer } from 'miragejs'; export default function() { createServer({ environment: 'test', routes() { /* ... */ } }); }`.Ensure `setupMirage(hooks)` is called for the current test module, and that any server interactions are within `beforeEach`, `afterEach`, or `test` blocks where `this.server` is guaranteed to be available.