question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Occasionally I want to make assertions about what requests are made during a test without changing the behaviour of an existing mocked endpoint. To accomplish this I’ve implemented and am using a method didRequest.

The didRequest method is called after mirage has intercepted and handled the request. It allows you to make assertions about a request without replacing an existing mirage request handler. For example if you have already defined a mirage request handler

this.server.get('http://example.org/users', function(schema, request) {
  return schema.users.all();
});

You can make assertions about the request

this.server.didRequest('GET', 'http://example.org/users', function(request) {
  assert.step('get users called');
});

You don’t need to replace the existing request handler with another similar one plus the assertion.

this.server.get('http://example.org/users', function(schema, request) {
  assert.step('get users called');
  return schema.users.all();
});

I’d like to submit a PR for this but before writing it I’d like to know if there would be any interest in merging it? Is it within scope of functionality mirage-js should provide?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
mrloopcommented, Sep 23, 2022

Thanks, have set it up in large mirage project and working through migration issues.

1reaction
cah-brian-gantzlercommented, Sep 19, 2022

The split is actually complete. Just Pretender is still part of MirageJS so if you use MSW you will still have pretender in the code until we do a PR to remove it. At that point it will be a breaking change. You will have to say use Pretender. Which means adding mirage-pretender to your package.json. You can do that now and it will use the mirage-pretender version of pretender instead of the pretender included in mirageJS

import { createServer } from "miragejs"
import PretenderInterceptor from 'mirage-pretender';

export default function () {
  createServer({
    interceptor: new PretenderInterceptor(),  
    routes() {
      this.get("/api/reminders", () => ({
        reminders: [],
      }))
    },
  })
}

That means that if you can add mirage-msw to your package.json and do

import { createServer } from "miragejs"
import PretenderInterceptor from 'mirage-msw';

export default function () {
  createServer({
    interceptor: new PretenderInterceptor(),  
    routes() {
      this.get("/api/reminders", () => ({
        reminders: [],
      }))
    },
  })
}

You can use MSW today. If you do would love to hear any feedback. The onMockResponse should be handled, but in a pretendery sort of way to make it backward compatible.

For this discussion the arrays for tracking requests are accessible via the pretender instance. You can access that in server.pretender in the response code. I dont know if MSW does anything like that, but if you are using MSW there will be a server.msw prop to access it. Those arrays should be getters on the interface to abstract away accessing them. However the data in the arrays will be different formats so abstract that as well? Not sure where to draw the line.

Interested in any thoughts and PRs on the interfaces.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DID Request - OneSuite
DID Request. Country/Area Code Request. We're here to help. FAQ; Call 1-866-417-8483; Email Us · Product Quick Glance. ^. OneSuite ISO 9001.
Read more >
Form 1051, Request for Determination of Intellectual Disability ...
Form 1051, Request for Determination of Intellectual Disability (DID) ... Date of DID Request – DFPS staff enters the date the DID is...
Read more >
"Why Did I Get This?" - Form Look Up
This page lists all Temporary Disability and Family Leave Insurance forms that may be sent to you, why you may have received them,...
Read more >
e-Request - Self Service Tools - USCIS Case Status
Case Inquiry · Case outside normal processing time · Did not receive notice by mail · Did not receive card by mail ·...
Read more >
DID / Number Requests - Telnyx Support
This article explains the process for requesting numbers of all kinds which may be unavailable to purchase from the Mission Control Portal.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found