# installFakeReplica

> **installFakeReplica**(`options?`): [`FakeReplica`](https://ic-reactor.b3pay.net/v3/libs/interfaces/fakereplica/)

Defined in: [core/src/testing/fake-replica.ts:466](https://github.com/B3Pay/ic-reactor/blob/f1956947ae037304fce1675a38695964c1aa9e32/packages/core/src/testing/fake-replica.ts#L466)

Stubs `globalThis.fetch` with a fake replica that runs `options.canisters`,
so a `Reactor`, a `DisplayReactor` and the hooks built on them run end to
end in a test, with no replica and nothing mocked in the agent.

Install it before the agents under test are built: an `HttpAgent` keeps the
`fetch` it found when it was built. A `ClientManager` built at module scope
is built when its module is first imported, so install the fake in a setup
file, or const BACKEND = "bkyz2-fmaaa-aaaaa-qaaaq-cai"
let replica: FakeReplica

beforeEach(() => {
  replica = installFakeReplica({
    canisters: {
      [BACKEND]: createTestCanister<_SERVICE>(idlFactory, {
        greet: ([name]) => `Hello, ${name}!`,
      }),
    },
  })
})
afterEach(() => replica.restore())

it("greets", async () => {
  const backend = new Reactor<_SERVICE>({
    clientManager: new ClientManager({
      queryClient: new QueryClient(),
      agentOptions: { host: replica.host },
    }),
    name: "backend",
    canisterId: BACKEND,
    idlFactory,
  })

  await expect(
    backend.fetchQuery({ functionName: "greet", args: ["Ada"] })
  ).resolves.toBe("Hello, Ada!")
})
```