<commit_before>---
title: .mock()
position: 1.1
description: Replaces `fetch` with a stub which records its calls and returns a `Response` instance.
parameters:
  - name: matcher
    content: `String`|`Regex`|`Function`: Rule for matching calls to `fetch`
  - name: response
    content: `String`|`Object`|`Function`|`Promise`: Response to send matched calls
  - name: options
    content: `Object`: More options configuring [mainly] matching behaviour
content_markdown: |-

  Alternatively a single parameters, `options`, and `Object` with `matcher`, `response` and other options defined on it, can be passed
  {: .info}



left_code_blocks:
  - code_block: |-
      $.post("http://api.myapp.com/books/", {
        "token": "YOUR_APP_KEY",
        "title": "The Book Thief",
        "score": 4.3
      }, function(data) {
        alert(data);
      });
    title: jQuery
    language: javascript
right_code_blocks:
  - code_block: |-<commit_msg>'mock'<commit_after>---
title: ".mock()"
position: 1.1
description: "Replaces `fetch` with a stub which records its calls and returns a `Response` instance."
parameters:
  - name: matcher
    content: "`String`|`Regex`|`Function`: Rule for matching calls to `fetch`"
  - name: response
    content: "`String`|`Object`|`Function`|`Promise`: Response to send matched calls"
  - name: options
    content: "`Object`: More options configuring [mainly] matching behaviour"
content_markdown: |-

  Alternatively a single parameters, `options`, and `Object` with `matcher`, `response` and other options defined on it, can be passed
  {: .info}



left_code_blocks:
  - code_block: |-
      $.post("http://api.myapp.com/books/", {
        "token": "YOUR_APP_KEY",
        "title": "The Book Thief",
        "score": 4.3
      }, function(data) {
        alert(data);
      });
    title: jQuery
    language: javascript
right_code_blocks:
  - code_block: |-
{'fraction_non_alphanumeric': 0.14142480211081795, 'fraction_numerical': 0.004221635883905013, 'mean_word_length': 3.440281030444965, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1827390', 'n_tokens_mistral': 610, 'n_tokens_neox': 577, 'n_words': 180}