Skip to content

Latest commit

 

History

History

with-jest-node

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Zimic + Jest + Node.js

This example uses Zimic with Jest in a server-side environment. Node.js is used in this example, but other runtimes should be similar, such as Deno and Bun.

Application

The application is a simple Fastify server, fetching repositories from the GitHub API. Any other Node.js framework could be used as well, such as express and Nest.js.

Testing

An example test suite uses Jest to test the application. Zimic is used to mock the GitHub API and simulate a test case where the repository is found and another where it is not.

Zimic

Test

Important

The flag --experimental-vm-modules, present in the command test in the package.json, is required by Jest because Zimic uses dynamic imports internally.

Running

  1. Clone this example:

    mkdir zimic
    cd zimic
    git init
    git remote add origin git@github.com:zimicjs/zimic.git
    git sparse-checkout init
    git sparse-checkout set examples/with-jest-node
    git pull origin canary # or a specific branch or tag
    cd examples/with-jest-node

    If you'd like to clone the example of a previous version, replace canary with the desired branch or tag, such as @zimic/interceptor@0 and @zimic/fetch@0.1.0.

  2. Install the dependencies:

    pnpm install
  3. Run the tests:

    pnpm run test