visiblevc / ember-msw

Integrates Ember with MSW and provides test helpers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ember-msw

Integrates Ember with MSW and provides test helpers.

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

Installation

ember install ember-msw

Installation notes:

  • MSW is a dependency and does not need to be installed separately
  • The addon hosts mockServiceWorker.js, so you don't need to generate one in your app

Usage

Setup

Steps to use the provided test helpers:

  1. Call setupRequestMocking in your test-helper.js
// tests/test-helper.js

// ...
import { setupRequestMocking } from 'ember-msw/test-support';  // <---
// ...

setApplication(Application.create(config.APP));

setup(QUnit.assert);

setupRequestMocking();  // <---

start();
  1. Use the setupRequestMockingTest and getWorker in your tests: see example.

Providing options to setupWorker

All argument to setupRequestMocking are forwarded to MSW's setupWorker:

// tests/test-helper.js

setupRequestMocking(
  rest.get('/assets/*', () => {}) // Pass through requests to /assets/*
);

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

About

Integrates Ember with MSW and provides test helpers

License:MIT License


Languages

Language:JavaScript 89.6%Language:HTML 9.0%Language:Handlebars 1.4%