Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of called(matcher) and others may be confusing #87

Closed
motiz88 opened this issue Apr 14, 2016 · 2 comments
Closed

Behavior of called(matcher) and others may be confusing #87

motiz88 opened this issue Apr 14, 2016 · 2 comments

Comments

@motiz88
Copy link
Contributor

motiz88 commented Apr 14, 2016

This is one of the two related issues that led me to submit #83 (the other is #88).

calls, called, lastCall, lastUrl. lastOptions are all documented as taking a matcher argument. This argument can only meaningfully be a string naming an existing route, and thus it differs subtly from the meaning of matcher in what's probably the most visible API, mock():

matcher [required]: Condition for selecting which requests to mock Accepts any of the following
* string: ...
* RegExp: ...
* Function(url, opts): ...

Here is a case where my (incorrect) reading of the docs led to surprising behavior:

fetchMock.mock('^http://example.com/');
fetch('http://example.com/one/two').then(() => {
  fetchMock.called('^http://example.com/'); // true
  fetchMock.called('^http://example.com/one'); // false (surprising to me)
  fetchMock.called(/one\/two$/); // false (surprising to me)
});
@wheresrhys
Copy link
Owner

The docs are now clearer on this point, using matcherName with details of how this is derived from matcher

@fredtma
Copy link

fredtma commented May 4, 2020

Hi,

I am struggling to get the fetchMock.called method to work. The above example all return false.
What am I doing wrong?

  it('Test', (done) => {
    fetchMock.mock('^http://example.com/', 200);
    fetch('http://example.com/one/two').then(() => {
      console.log('==========');
      console.log(fetchMock.called('^http://example.com/')); // false
      console.log(fetchMock.called('^http://example.com/one')); // false 
      console.log(fetchMock.called(/one\/two$/)); // false
      done();
    });
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants