Packages
@runtime-edge/jest-environment

Runtime Edge Jest Environment

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

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

Installation

npm install @runtime-edge/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 Runtime Edge:

// jest --env @runtime-edge/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)
})