Packages
@edge-runtime/jest-environment

Edge Runtime Jest Environment

The @edge-runtime/jest-environment package enables you to run Jest (opens in a new tab) tests against the Edge Runtime environment.

It helps you to write tests assertion without being worried about the environment setup.

Installation

npm install @edge-runtime/jest-environment

Usage

Jest enables you to define the test environment through a code comment (opens in a new tab) or as a CLI option (opens in a new tab).

For example, the following test would pass:

// jest --env node
// ✅ Pass
it('should return the correct value', () => {
  let val = eval('2 + 2')
  expect(val).toBe(4)
})

The following test would fail when using the Edge Runtime:

// jest --env @edge-runtime/jest-environment
// ❌ Fail
// Error name:    "EvalError"
// Error message: "Code generation from strings disallowed for this context"
it('should return the correct value', () => {
  let val = eval('2 + 2')
  expect(val).toBe(4)
})