Jest test runner integration with Jasmine 2.x framework providing BDD-style testing capabilities
npx @tessl/cli install tessl/npm-jest-jasmine2@30.1.00
# Jest Jasmine2
1
2
Jest Jasmine2 is a Jest test runner adapter that integrates the Jasmine 2.x testing framework with Jest's testing environment. It provides a bridge between Jest's modern testing infrastructure and Jasmine's behavior-driven development (BDD) testing style, offering features like describe/it syntax, async test support, custom matchers, and test suite organization.
3
4
## Package Information
5
6
- **Package Name**: jest-jasmine2
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: Part of Jest monorepo - typically installed via Jest
10
11
## Core Imports
12
13
```typescript
14
import jasmine2 from "jest-jasmine2";
15
import type { Jasmine, Reporter } from "jest-jasmine2";
16
```
17
18
For CommonJS:
19
20
```javascript
21
const jasmine2 = require("jest-jasmine2").default;
22
```
23
24
## Basic Usage
25
26
Jest Jasmine2 is primarily used internally by Jest as a test runner. It integrates with Jest's configuration and runtime systems:
27
28
```typescript
29
import jasmine2 from "jest-jasmine2";
30
import type { Config } from "@jest/types";
31
import type { JestEnvironment } from "@jest/environment";
32
import type Runtime from "jest-runtime";
33
34
// Used within Jest's test execution pipeline
35
const result = await jasmine2(
36
globalConfig,
37
config,
38
environment,
39
runtime,
40
testPath
41
);
42
```
43
44
## Architecture
45
46
Jest Jasmine2 is built around several key components:
47
48
- **Main Test Runner**: The `jasmine2` function orchestrates test execution by integrating Jest configuration with Jasmine's test framework
49
- **Jasmine Integration**: Custom Jasmine 2.x implementation with Jest-specific enhancements for async support, mocking, and snapshot testing
50
- **Reporter System**: Converts Jasmine test results into Jest's TestResult format for consistent reporting
51
- **BDD Interface**: Provides familiar describe/it syntax and lifecycle hooks (beforeEach, afterEach, etc.)
52
- **Async Support**: Enhanced async/await and Promise support for modern JavaScript testing patterns
53
- **Global Extensions**: Installs testing utilities like spies, matchers, and Jest-specific features into the global environment
54
55
## Capabilities
56
57
### Main Test Runner
58
59
The primary function that executes Jasmine tests within Jest's environment, handling configuration, setup, and result reporting.
60
61
```typescript { .api }
62
function jasmine2(
63
globalConfig: Config.GlobalConfig,
64
config: Config.ProjectConfig,
65
environment: JestEnvironment,
66
runtime: Runtime,
67
testPath: string,
68
): Promise<TestResult>;
69
```
70
71
[Test Runner](./test-runner.md)
72
73
### Test Reporting
74
75
Jasmine to Jest test result reporting system that converts Jasmine's test results into Jest's standardized format.
76
77
```typescript { .api }
78
class JasmineReporter implements Reporter {
79
constructor(
80
globalConfig: Config.GlobalConfig,
81
config: Config.ProjectConfig,
82
testPath: string,
83
);
84
85
getResults(): Promise<TestResult>;
86
specDone(result: SpecResult): void;
87
jasmineDone(runDetails: RunDetails): void;
88
}
89
90
interface Reporter {
91
jasmineDone(runDetails: RunDetails): void;
92
jasmineStarted(runDetails: RunDetails): void;
93
specDone(result: SpecResult): void;
94
specStarted(spec: SpecResult): void;
95
suiteDone(result: SuiteResult): void;
96
suiteStarted(result: SuiteResult): void;
97
}
98
```
99
100
[Reporting](./reporting.md)
101
102
### Jasmine Framework
103
104
Core Jasmine 2.x implementation with Jest-specific enhancements for test execution, spying, and BDD syntax.
105
106
```typescript { .api }
107
interface Jasmine {
108
_DEFAULT_TIMEOUT_INTERVAL: number;
109
DEFAULT_TIMEOUT_INTERVAL: number;
110
currentEnv_: ReturnType<typeof Env>['prototype'];
111
getEnv(): ReturnType<typeof Env>['prototype'];
112
createSpy: typeof createSpy;
113
addMatchers(matchers: JasmineMatchersObject): void;
114
version: string;
115
testPath: string;
116
}
117
118
function create(createOptions: Record<string, any>): Jasmine;
119
120
function _interface(jasmine: Jasmine, env: any): {
121
describe(description: string, specDefinitions: SpecDefinitionsFn): any;
122
it(): any;
123
beforeEach(): any;
124
afterEach(): any;
125
beforeAll(): any;
126
afterAll(): any;
127
spyOn(obj: Record<string, any>, methodName: string, accessType?: string): Spy;
128
fail(): void;
129
pending(): void;
130
}
131
```
132
133
[Jasmine Framework](./jasmine-framework.md)
134
135
### Async Testing Support
136
137
Enhanced async/await and Promise support for test functions and lifecycle hooks, with generator function support.
138
139
```typescript { .api }
140
function jasmineAsyncInstall(
141
globalConfig: Config.GlobalConfig,
142
global: Global.Global,
143
): void;
144
```
145
146
[Async Support](./async-support.md)
147
148
### Jest Integration
149
150
Setup functions that integrate Jest-specific features like snapshots, expect matchers, and global utilities.
151
152
```typescript { .api }
153
function setupJestGlobals(options: SetupOptions): Promise<SnapshotState>;
154
155
interface SetupOptions {
156
config: Config.ProjectConfig;
157
globalConfig: Config.GlobalConfig;
158
localRequire: (moduleName: string) => Plugin;
159
testPath: string;
160
}
161
162
function installEach(environment: JestEnvironment): void;
163
```
164
165
[Jest Integration](./jest-integration.md)
166
167
## Core Types
168
169
```typescript { .api }
170
interface SpecDefinitionsFn {
171
(): void;
172
}
173
174
interface AssertionErrorWithStack extends AssertionError {
175
stack: string;
176
}
177
178
interface RunDetails {
179
totalSpecsDefined?: number;
180
failedExpectations?: SuiteResult['failedExpectations'];
181
}
182
183
interface Spy extends Record<string, any> {
184
(this: Record<string, unknown>, ...args: Array<any>): unknown;
185
and: SpyStrategy;
186
calls: CallTracker;
187
restoreObjectToOriginalState?: () => void;
188
}
189
190
interface JasmineMatchersObject {
191
[id: string]: JasmineMatcher;
192
}
193
194
interface JasmineMatcher {
195
(matchersUtil: unknown, context: unknown): JasmineMatcher;
196
compare(...args: Array<unknown>): unknown;
197
negativeCompare(...args: Array<unknown>): unknown;
198
}
199
```