Registry / testing / ember-cli-mirage

ember-cli-mirage

JSON →
library3.0.4jsnpmunverified

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-mirage
INSTALL
IMPORT
SIG · EMBER-CLI-MIRAGE
E
ember-cli-mirage
testingjavascriptv3.0.4
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

setupMirage
✓ import { setupMirage } from 'ember-cli-mirage/test-support';
✗ import { setupMirage } from 'ember-cli-mirage';
This helper is specifically for test setups and is imported from `test-support`. Available since v3.0.0-alpha.3 with TypeScript declarations.
createServer
✓ import { createServer } from 'miragejs';
✗ import { Server } from 'ember-cli-mirage'; new Server(...);
Since v3.0.0-alpha.2, you must import `createServer` directly from `miragejs` and use it within your `mirage/config.js`. The `ember-cli-mirage` Server class was removed.
Response
✓ import { Response } from 'miragejs';
✗ import Response from 'ember-cli-mirage/response';
For custom HTTP responses, `Response` should be imported directly from `miragejs`. Re-exports from `ember-cli-mirage` were removed in v3.0.0-alpha.1.

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.

import Application from '@ember/application'; import config from './config/environment'; import loadInitializers from 'ember-load-initializers'; // app/mirage/config.js // This file is automatically loaded by ember-cli-mirage. // It's where you define your API routes, factories, and serializers. export default function() { this.get('/posts', function(schema, request) { return schema.posts.all(); }); this.post('/posts', function(schema, request) { let attrs = JSON.parse(request.requestBody); return schema.posts.create(attrs); }); this.passthrough('/users/**'); // Example of proxying requests } // tests/test-helper.js (example usage in a test) import resolver from './helpers/resolver'; import { setApplication } from '@ember/test-helpers'; import { start } from 'ember-qunit'; import { setupMirage } from 'ember-cli-mirage/test-support'; setApplication(Application.create(config.APP)); module('Integration | Component | my-component', function(hooks) { setupApplicationTest(hooks); setupMirage(hooks); // This will start Mirage for your tests test('it renders posts', async function(assert) { this.server.createList('post', 3); // Create some mock data await render(hbs`<MyComponent />`); assert.dom('.post').exists({ count: 3 }); }); });
Debug
Known issues
breaking`miragejs` is now a peer dependency and must be explicitly installed. This means you need to add `npm install miragejs` to your project.
fix
Run `npm install miragejs` (or `yarn add miragejs`) in your project root after upgrading to `ember-cli-mirage@3.x`.
affects: >=3.0.0
breakingThe `ember-cli-mirage` Server class has been removed. You must now use `createServer` imported directly from `miragejs` in your `mirage/config.js`.
fix
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`.
affects: >=3.0.0-alpha.2
breakingDeprecated re-exports from `ember-cli-mirage` (like `Response`, `Factory`, `Model`, etc.) which were originally from `miragejs` have been removed. You must import these directly from `miragejs`.
fix
Replace `import { Response } from 'ember-cli-mirage/response';` (and similar re-exports) with `import { Response } from 'miragejs';`.
affects: >=3.0.0-alpha.1
breakingSupport for older Ember.js and Node.js versions has been dropped. `ember-cli-mirage@3.x` requires Ember.js v3.28+ and Node.js v16+.
fix
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.
affects: >=3.0.0
gotchaIn a testing environment, `setupMirage(hooks)` should be called to properly initialize the Mirage server for each test module. For acceptance tests, `setupApplicationTest(hooks)` also initializes Mirage if configured.
fix
Always include `setupMirage(hooks);` within your QUnit or Mocha `module()` setup function for tests that interact with Mirage.
affects: All
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'miragejs'
The `miragejs` package is a peer dependency since `ember-cli-mirage@3.x` but has not been installed.
fix
Run `npm install miragejs` or `yarn add miragejs` to add the core library to your project's dependencies.
TypeError: (0 , ember_cli_mirage__WEBPACK_IMPORTED_MODULE_2__.Server) is not a constructor
Attempting to instantiate `Server` from `ember-cli-mirage` in `mirage/config.js`, which was removed in v3.0.0-alpha.2.
fix
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() { /* ... */ } }); }`.
TypeError: Cannot read properties of undefined (reading 'schema') in MirageJS
This often occurs when `this.server.create(...)` or `this.server.schema(...)` is called outside the context where Mirage's server is properly initialized, such as within a test hook but before `setupMirage` has run, or in an incorrect context.
fix
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.
Upgrade
Version history
3.0.4latest on npm
Audit
Dependencies
miragejsrequiredCore mocking library; became a peer dependency in v3.0.0.
@ember-data/modelrequiredRequired for integration with Ember Data models.
@ember/test-helpersrequiredUsed for setting up Mirage in testing environments.
ember-datarequiredRequired for integration with Ember Data (older versions or compatibility).
ember-qunitrequiredUsed in testing environments, particularly with QUnit.
ember-sourcerequiredCore Ember.js framework dependency.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources