# `Twilio.Test`
[🔗](https://github.com/jeffhuen/twilio_elixir/blob/main/lib/twilio/test.ex#L1)

Test helpers for stubbing Twilio HTTP requests.

Uses NimbleOwnership for per-process stub isolation,
enabling `async: true` tests.

## Usage

    setup do
      Twilio.Test.stub(fn method, url, headers, body ->
        {200, [], ~s({"sid": "SM123"})}
      end)

      client = Twilio.client("ACtest", "token")
      {:ok, client: client}
    end

    test "sends a message", %{client: client} do
      assert {:ok, msg} = Twilio.Api.V2010.MessageService.create(client, params)
      assert msg["sid"] == "SM123"
    end

# `allow`

```elixir
@spec allow(pid()) :: :ok
```

Allow another process to use the current process's stub.

# `start`

Start the ownership server. Called from test_helper.exs.

# `stub`

```elixir
@spec stub((String.t(), String.t(), list(), String.t() | nil -&gt;
        {integer(), list(), String.t()})) :: :ok
```

Register a stub function for the current test process.

The function receives `(method, url, headers, body)` and must return
`{status, headers, body}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
