or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

async-support.mdindex.mdjasmine-framework.mdjest-integration.mdreporting.mdtest-runner.md
tile.json

jasmine-framework.mddocs/

0

# Jasmine Framework

1

2

Core Jasmine 2.x implementation with Jest-specific enhancements for test execution, spying, and BDD syntax.

3

4

## Capabilities

5

6

### Jasmine Instance Creation

7

8

Factory function that creates a configured Jasmine instance with Jest-specific enhancements.

9

10

```typescript { .api }

11

/**

12

* Creates a new Jasmine instance with Jest-specific configuration

13

* @param createOptions - Configuration options for the Jasmine instance

14

* @returns Configured Jasmine instance

15

*/

16

function create(createOptions: Record<string, any>): Jasmine;

17

```

18

19

### Jasmine Interface

20

21

The main Jasmine interface providing access to core functionality and configuration.

22

23

```typescript { .api }

24

/**

25

* Main Jasmine interface with Jest-specific enhancements

26

*/

27

interface Jasmine {

28

/** Internal default timeout interval */

29

_DEFAULT_TIMEOUT_INTERVAL: number;

30

/** Default timeout interval for tests (configurable) */

31

DEFAULT_TIMEOUT_INTERVAL: number;

32

/** Current test environment instance */

33

currentEnv_: ReturnType<typeof Env>['prototype'];

34

/** Test path being executed */

35

testPath: string;

36

/** Jasmine version string */

37

version: string;

38

39

/** Get the current test environment */

40

getEnv(): ReturnType<typeof Env>['prototype'];

41

/** Create a spy function */

42

createSpy: typeof createSpy;

43

/** Add custom matchers to the test environment */

44

addMatchers(matchers: JasmineMatchersObject): void;

45

46

// Jasmine class constructors

47

Env: ReturnType<typeof Env>;

48

JsApiReporter: typeof JsApiReporter;

49

ReportDispatcher: typeof ReportDispatcher;

50

Spec: typeof Spec;

51

SpyRegistry: typeof SpyRegistry;

52

Suite: typeof Suite;

53

Timer: typeof Timer;

54

}

55

```

56

57

### BDD Interface Creation

58

59

Creates the BDD interface that provides describe, it, and other testing functions.

60

61

```typescript { .api }

62

/**

63

* Creates the BDD interface for test writing

64

* @param jasmine - The Jasmine instance

65

* @param env - The test environment

66

* @returns Object containing BDD functions

67

*/

68

function _interface(jasmine: Jasmine, env: any): BDDInterface;

69

70

interface BDDInterface {

71

/** Define a test suite */

72

describe(description: string, specDefinitions: SpecDefinitionsFn): Suite;

73

/** Define a disabled/skipped test suite */

74

xdescribe(description: string, specDefinitions: SpecDefinitionsFn): Suite;

75

/** Define a focused test suite (only this suite runs) */

76

fdescribe(description: string, specDefinitions: SpecDefinitionsFn): Suite;

77

78

/** Define a test specification */

79

it(description: string, testFn?: TestFn, timeout?: number): Spec;

80

/** Define a disabled/skipped test */

81

xit(description: string, testFn?: TestFn, timeout?: number): Spec;

82

/** Define a focused test (only this test runs) */

83

fit(description: string, testFn?: TestFn, timeout?: number): Spec;

84

85

/** Setup function to run before each test */

86

beforeEach(setupFn: SetupFn, timeout?: number): void;

87

/** Teardown function to run after each test */

88

afterEach(teardownFn: TeardownFn, timeout?: number): void;

89

/** Setup function to run before all tests in suite */

90

beforeAll(setupFn: SetupFn, timeout?: number): void;

91

/** Teardown function to run after all tests in suite */

92

afterAll(teardownFn: TeardownFn, timeout?: number): void;

93

94

/** Mark a test as pending */

95

pending(): void;

96

/** Explicitly fail a test */

97

fail(message?: string): void;

98

99

/** Create a spy on an object method */

100

spyOn(obj: Record<string, any>, methodName: string, accessType?: string): Spy;

101

102

/** Jasmine API reporter instance */

103

jsApiReporter: JsApiReporter;

104

/** Reference to the Jasmine instance */

105

jasmine: Jasmine;

106

}

107

```

108

109

### Test Environment

110

111

The Jasmine test environment that manages test execution and state.

112

113

```typescript { .api }

114

/**

115

* Jasmine test environment managing test execution

116

*/

117

interface JasmineEnv {

118

/** Execute all registered tests */

119

execute(): Promise<void>;

120

121

/** Add a reporter to receive test events */

122

addReporter(reporter: Reporter): void;

123

124

/** Filter function for specs */

125

specFilter?: (spec: Spec) => boolean;

126

127

/** Register a test suite */

128

describe(description: string, specDefinitions: SpecDefinitionsFn): Suite;

129

130

/** Register a test specification */

131

it(description: string, testFn?: TestFn, timeout?: number): Spec;

132

133

/** Setup/teardown hooks */

134

beforeEach(setupFn: SetupFn, timeout?: number): void;

135

afterEach(teardownFn: TeardownFn, timeout?: number): void;

136

beforeAll(setupFn: SetupFn, timeout?: number): void;

137

afterAll(teardownFn: TeardownFn, timeout?: number): void;

138

139

/** Test control functions */

140

pending(): void;

141

fail(message?: string): void;

142

143

/** Spy creation */

144

spyOn(obj: Record<string, any>, methodName: string, accessType?: string): Spy;

145

146

/** Todo test marker */

147

todo(description: string): Spec;

148

}

149

```

150

151

### Spy System

152

153

Jasmine's spy functionality for mocking and tracking function calls.

154

155

```typescript { .api }

156

/**

157

* Creates a spy function for testing

158

* @param name - Optional name for the spy

159

* @param originalFn - Optional original function to spy on

160

* @returns Spy function with tracking capabilities

161

*/

162

function createSpy(name?: string, originalFn?: Function): Spy;

163

164

/**

165

* Spy object with call tracking and behavior modification

166

*/

167

interface Spy extends Record<string, any> {

168

/** The spy function itself */

169

(this: Record<string, unknown>, ...args: Array<any>): unknown;

170

171

/** Spy behavior configuration */

172

and: SpyStrategy;

173

174

/** Call tracking information */

175

calls: CallTracker;

176

177

/** Restore original object state (for spyOn) */

178

restoreObjectToOriginalState?: () => void;

179

}

180

181

/**

182

* Spy behavior strategy for configuring return values and call behavior

183

*/

184

interface SpyStrategy {

185

/** Return a specific value */

186

returnValue(value: any): Spy;

187

188

/** Return different values in sequence */

189

returnValues(...values: any[]): Spy;

190

191

/** Call the original function */

192

callThrough(): Spy;

193

194

/** Call a fake function instead */

195

callFake(fn: Function): Spy;

196

197

/** Throw an error when called */

198

throwError(errorMsg?: string | Error): Spy;

199

200

/** Reset the spy to default behavior */

201

stub(): Spy;

202

}

203

204

/**

205

* Call tracking for spy functions

206

*/

207

interface CallTracker {

208

/** Whether the spy has been called */

209

any(): boolean;

210

211

/** Number of times the spy was called */

212

count(): number;

213

214

/** Arguments from a specific call */

215

argsFor(index: number): any[];

216

217

/** All calls made to the spy */

218

allArgs(): any[][];

219

220

/** All calls with context information */

221

all(): Array<{

222

object: any;

223

args: any[];

224

returnValue: any;

225

}>;

226

227

/** Most recent call */

228

mostRecent(): {

229

object: any;

230

args: any[];

231

returnValue: any;

232

};

233

234

/** First call made */

235

first(): {

236

object: any;

237

args: any[];

238

returnValue: any;

239

};

240

241

/** Reset call tracking */

242

reset(): void;

243

}

244

```

245

246

### Custom Matchers

247

248

System for adding custom assertion matchers to Jasmine.

249

250

```typescript { .api }

251

/**

252

* Collection of custom matchers

253

*/

254

interface JasmineMatchersObject {

255

[matcherName: string]: JasmineMatcher;

256

}

257

258

/**

259

* Individual matcher function

260

*/

261

interface JasmineMatcher {

262

/** Matcher factory function */

263

(matchersUtil: MatchersUtil, context: MatcherContext): {

264

compare(actual: any, ...expected: any[]): MatcherResult;

265

negativeCompare?(actual: any, ...expected: any[]): MatcherResult;

266

};

267

}

268

269

interface MatcherResult {

270

pass: boolean;

271

message: string | (() => string);

272

}

273

274

interface MatchersUtil {

275

equals(a: any, b: any): boolean;

276

contains(haystack: any, needle: any): boolean;

277

buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: any[]): string;

278

}

279

280

interface MatcherContext {

281

isNot?: boolean;

282

actual?: any;

283

}

284

```

285

286

**Usage Examples:**

287

288

```typescript

289

import { create, _interface } from "jest-jasmine2/build/jasmine/jasmineLight";

290

291

// Create Jasmine instance

292

const jasmine = create({

293

testTimeout: 5000,

294

testPath: "/path/to/test.js"

295

});

296

297

// Get test environment

298

const env = jasmine.getEnv();

299

300

// Create BDD interface

301

const bddInterface = _interface(jasmine, env);

302

303

// Use BDD functions

304

bddInterface.describe("Test Suite", () => {

305

bddInterface.it("should work", () => {

306

expect(true).toBe(true);

307

});

308

});

309

310

// Create spies

311

const spy = jasmine.createSpy("testSpy");

312

spy.and.returnValue("mocked value");

313

314

const objectSpy = bddInterface.spyOn(obj, "method");

315

expect(objectSpy).toHaveBeenCalled();

316

```