{"id":16998,"library":"ember-cli-pretender","title":"Ember CLI Pretender Integration","description":"ember-cli-pretender is an Ember CLI addon designed to simplify the integration of the `pretender.js` HTTP mocking library into Ember applications. It abstracts away the manual import process of `pretender.js` files, making the `Pretender` constructor directly importable within the Ember app's testing environment. The current stable version is 4.0.0, which was released in 2020. While no longer under active, frequent development, it continues to serve its purpose for existing Ember projects. Key differentiators include its tight integration with the Ember CLI build pipeline, allowing developers to enable `pretender.js` conditionally (e.g., only for tests or also for production builds) and to opt out of polyfills like `fetch`. This addon is crucial for writing robust and isolated unit and integration tests that interact with network requests without relying on live backend services. Its release cadence has been infrequent, with the last major update several years ago, indicating a maintenance phase rather than active development.","status":"maintenance","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/rwjblue/ember-cli-pretender","tags":["javascript","ember-addon"],"install":[{"cmd":"npm install ember-cli-pretender","lang":"bash","label":"npm"},{"cmd":"yarn add ember-cli-pretender","lang":"bash","label":"yarn"},{"cmd":"pnpm add ember-cli-pretender","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core HTTP mocking library that this addon integrates and makes available.","package":"pretender","optional":false},{"reason":"Build-time dependency that handles Babel transpilation for the Ember CLI environment; upgraded to v7 in `ember-cli-pretender` v4.0.0.","package":"ember-cli-babel","optional":false}],"imports":[{"note":"This imports the `Pretender` constructor from the underlying `pretender.js` library, which `ember-cli-pretender` makes available through the Ember CLI build pipeline. CommonJS `require` is generally not used in modern Ember applications.","wrong":"const Pretender = require('pretender');","symbol":"Pretender","correct":"import Pretender from 'pretender';"},{"note":"Configuration is handled via the `EmberApp` constructor options, not via direct imports. This allows global control over Pretender's availability and features within the Ember application build.","symbol":"App configuration","correct":"// In ember-cli-build.js or Brocfile.js\nvar app = new EmberApp({\n  pretender: {\n    enabled: true, // or app.tests\n    includeFetchPolyfill: false\n  }\n});"}],"quickstart":{"code":"import Pretender from 'pretender';\nimport { module, test } from 'qunit';\nimport { setupTest } from 'ember-qunit';\n\nmodule('Unit | Utility | my-service', function(hooks) {\n  setupTest(hooks);\n\n  let server;\n\n  hooks.beforeEach(function() {\n    server = new Pretender(function() {\n      this.get('/api/users', function() {\n        return [200, { 'Content-Type': 'application/json' }, JSON.stringify([{ id: 1, name: 'Alice' }])];\n      });\n      this.post('/api/users', function(request) {\n        const newUser = JSON.parse(request.requestBody);\n        return [201, { 'Content-Type': 'application/json' }, JSON.stringify({ id: 2, name: newUser.name })];\n      });\n    });\n  });\n\n  hooks.afterEach(function() {\n    server.shutdown();\n  });\n\n  test('it can fetch users', async function(assert) {\n    const response = await fetch('/api/users');\n    const data = await response.json();\n    assert.deepEqual(data, [{ id: 1, name: 'Alice' }], 'should return mocked users');\n  });\n\n  test('it can create a user', async function(assert) {\n    const response = await fetch('/api/users', {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json' },\n      body: JSON.stringify({ name: 'Bob' })\n    });\n    const data = await response.json();\n    assert.deepEqual(data, { id: 2, name: 'Bob' }, 'should return created user');\n    assert.equal(response.status, 201, 'should return 201 status');\n  });\n});","lang":"javascript","description":"This quickstart demonstrates how to install `ember-cli-pretender`, import `Pretender` in an Ember QUnit test, set up a mock server with `get` and `post` routes, and make `fetch` requests against it, then shut it down."},"warnings":[{"fix":"Upgrade your Node.js environment to version 10 or higher. For Ember CLI projects, consult your `package.json` engines field and `ember-cli` version compatibility.","message":"Version 4.0.0 of `ember-cli-pretender` dropped support for Node.js versions older than 10. Applications running on Node.js 8 or earlier will encounter build failures or runtime issues.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Ensure your Ember CLI project is compatible with `ember-cli-babel` v7. Review your Babel configuration (`babel.config.js` or `.babelrc`) for any breaking changes introduced in Babel 7, and update other related Ember addons if necessary.","message":"Version 4.0.0 upgraded the underlying `ember-cli-babel` dependency to v7. This may introduce compatibility issues with older Ember CLI projects or custom Babel configurations, potentially leading to build errors.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade `ember-cli-pretender` to at least v3.2.0 to ensure better compatibility with `ember-auto-import`. If issues persist, refer to the documentation for both addons for any specific configuration instructions.","message":"When `ember-auto-import` is also a dependency in your project, ensure `ember-cli-pretender` is correctly integrated. Older versions of `ember-cli-pretender` (prior to v3.2.0) had specific warnings or potential conflicts when used alongside `ember-auto-import`.","severity":"gotcha","affected_versions":"<3.2.0"},{"fix":"Relocate `ember-cli-pretender` from `devDependencies` to `dependencies` in your addon's `package.json` to ensure it is correctly installed and available for consumers of your addon.","message":"If you are developing an Ember addon that uses `ember-cli-pretender` to provide mocking functionality, `ember-cli-pretender` must be listed in your addon's `dependencies` in `package.json`, not `devDependencies`.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure `import Pretender from 'pretender';` is present at the top of your test file. Also, verify that `pretender.enabled` is set to `true` or `app.tests` in your `ember-cli-build.js` for the relevant build scenario.","cause":"`Pretender` was not correctly imported or `ember-cli-pretender` is not enabled for the current build environment.","error":"ReferenceError: Pretender is not defined"},{"fix":"Update your Node.js environment to version 10 or newer. Use a Node Version Manager (NVM) to easily switch Node.js versions for your project.","cause":"Attempting to use `ember-cli-pretender` v4.0.0 or later with a Node.js version older than 10.","error":"Error: Your application is using an unsupported Node.js version."},{"fix":"Add a `this.get('/api/data', ...)` or appropriate HTTP verb handler to your `Pretender` instance to mock the unhandled request. Ensure the URL and method match exactly.","cause":"A network request was made that was not explicitly mocked by the `Pretender` server.","error":"Pretender.js: Unhandled request GET /api/data"}],"ecosystem":"npm","meta_description":null}