Skip to content

Commit

Permalink
32129139: Convert our test suite to Jest
Browse files Browse the repository at this point in the history
Jest is modern and maintained. It also comes with code coverage for
free.
  • Loading branch information
DamienCassou committed Apr 3, 2024
1 parent d379aae commit 57f33ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"devDependencies": {
"@foretagsplatsen/eslint-plugin": "^6.0.0",
"@jest/globals": "^29.7.0",
"electron": "^29.1.6",
"eslint": "^8.57.0",
"jest": "^29.7.0"
Expand Down
25 changes: 13 additions & 12 deletions test/events.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import event from "../src/event.js";
import eventCategory from "../src/eventCategory.js";
import events from "../src/eventManager.js";
import { jest } from "@jest/globals";

describe("events", () => {
it("Bind callback to event", () => {
// Arrange: an event
let anEvent = event();
let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// Act: bind a callback
anEvent.register(spy);
Expand All @@ -21,8 +22,8 @@ describe("events", () => {
it("Bind multiple callbacks to an event", () => {
// Arrange: an event
let anEvent = event();
let spy1 = jasmine.createSpy("callback1");
let spy2 = jasmine.createSpy("callback2");
let spy1 = jest.fn();
let spy2 = jest.fn();

// Act: bind two callbacks and trigger event
anEvent.register(spy1);
Expand All @@ -39,7 +40,7 @@ describe("events", () => {
// Arrange: an event
let anEvent = event();

let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// Act: bind two callbacks and trigger event
anEvent.register(spy);
Expand All @@ -55,7 +56,7 @@ describe("events", () => {
// Arrange: an event
let anEvent = event();

let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// Act: bind two callbacks and trigger event
anEvent.register(() => {
Expand All @@ -75,8 +76,8 @@ describe("events", () => {
it("Trigger pass values to callbacks", () => {
// Arrange: an event
let anEvent = event();
let spy1 = jasmine.createSpy("callback1");
let spy2 = jasmine.createSpy("callback2");
let spy1 = jest.fn();
let spy2 = jest.fn();

// Act: bind two callbacks and trigger event
anEvent.register(spy1);
Expand All @@ -92,7 +93,7 @@ describe("events", () => {
it("Un-Bind callback using unregister", () => {
// Arrange: an event
let anEvent = event();
let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// bind a callback
let eventBinding = anEvent.register(spy);
Expand All @@ -108,7 +109,7 @@ describe("events", () => {
it("Un-Bind callback using unbind", () => {
// Arrange: an event
let anEvent = event();
let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// bind a callback
let eventBinding = anEvent.register(spy);
Expand All @@ -124,7 +125,7 @@ describe("events", () => {
it("Bind and trigger callback only once using registerOnce", () => {
// Arrange: an event
let anEvent = event();
let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// Act: bind a callback
anEvent.registerOnce(spy);
Expand Down Expand Up @@ -189,7 +190,7 @@ describe("events", () => {
// Arrange: an event
let someEvents = eventCategory();
let anEvent = someEvents.createEvent("namedEvent");
let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// bind a callback
let eventBinding = someEvents.register("namedEvent", spy);
Expand All @@ -206,7 +207,7 @@ describe("events", () => {
// Arrange: an event
let someEvents = eventCategory();
let anEvent = someEvents.createEvent("namedEvent");
let spy = jasmine.createSpy("callback");
let spy = jest.fn();

// Act: bind a callback
someEvents.registerOnce("namedEvent", spy);
Expand Down

0 comments on commit 57f33ca

Please sign in to comment.