Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.05 KB

jest-environment.mdx

File metadata and controls

39 lines (29 loc) · 1.05 KB

Edge Runtime Jest Environment

The @edge-runtime/jest-environment package enables you to run Jest 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 or as a CLI option.

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)
})