Skip to content

Commit

Permalink
Replace legacy Jasmine dependency in tests with Jest builtin
Browse files Browse the repository at this point in the history
The global `jasmine` API has been removed from Jest with the new test
runner `jest-circus` introduced in v27–v29. While possible to import the
legacy Jasmine package, it seemed to be more robust to upgrade to the
`jest.fn` API which behaves exactly the same as `jasmine.createSpy`.

The main difference is the `callThrough()` method in Jasmine spies. This
behaviour is the default for `jest.fn()`, so the upgrade works as-is.
  • Loading branch information
maetl committed Apr 6, 2024
1 parent ec73f77 commit f72fcca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@babel/preset-env": "7.24.4",
"@rollup/plugin-babel": "6.0.4",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-terser": "0.4.4",
"@types/jest": "29.5.12",
"@types/node": "^20.12.5",
"@typescript-eslint/eslint-plugin": "7.5.0",
Expand All @@ -44,7 +45,6 @@
"remap-istanbul": "0.13.0",
"rollup": "4.14.0",
"rollup-plugin-sourcemaps": "0.6.3",
"@rollup/plugin-terser": "0.4.4",
"rollup-plugin-typescript2": "0.36.0",
"ts-jest": "29.1.2",
"ts-node": "^10.9.2",
Expand Down
27 changes: 12 additions & 15 deletions src/tests/specs/inkjs/engine/Integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe("Integration", () => {
expect(context.story.variablesState["observedVar1"]).toEqual(1);
expect(context.story.variablesState["observedVar2"]).toEqual(2);

const spy1 = jasmine.createSpy("variable observer spy 1");
const spy2 = jasmine.createSpy("variable observer spy 2");
const commonSpy = jasmine.createSpy("variable observer spy common");
const spy1 = jest.fn().mockName("variable observer spy 1");
const spy2 = jest.fn().mockName("variable observer spy 2");
const commonSpy = jest.fn().mockName("variable observer spy common");
context.story.ObserveVariable("observedVar1", spy1);
context.story.ObserveVariable("observedVar2", spy2);
context.story.ObserveVariable("observedVar1", commonSpy);
Expand Down Expand Up @@ -199,11 +199,8 @@ describe("Integration", () => {
it("should call external functions", () => {
context.story.allowExternalFunctionFallbacks = false;
context.story.ChoosePathString("integration.external");
const externalSpy = jasmine
.createSpy("external function spy", (a) => {
return a;
})
.and.callThrough();

const externalSpy = jest.fn(a => a).mockName("external function spy");
context.story.BindExternalFunction("fn_ext", externalSpy);
context.story.BindExternalFunction("gameInc", () => undefined);

Expand All @@ -216,13 +213,13 @@ describe("Integration", () => {

it("should handle callstack changes", () => {
context.story.allowExternalFunctionFallbacks = false;
const externalSpy = jasmine
.createSpy("external function spy", (x) => {
x++;
x = parseInt(context.story.EvaluateFunction("inkInc", [x]));
return x;
})
.and.callThrough();

const externalSpy = jest.fn(x => {
x++;
x = parseInt(context.story.EvaluateFunction("inkInc", [x]));
return x;
}).mockName("external function spy");

context.story.BindExternalFunction("fn_ext", () => undefined);
context.story.BindExternalFunction("gameInc", externalSpy);

Expand Down

0 comments on commit f72fcca

Please sign in to comment.