-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: revert formatting changes to conform to StandardJS
- Loading branch information
1 parent
4e5c223
commit b89b1c5
Showing
1 changed file
with
60 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
/* eslint-env mocha */ | ||
|
||
import sbp from "@sbp/sbp"; | ||
import assert from "node:assert/strict"; | ||
import { describe, it, mock } from "node:test"; | ||
import "../dist/esm/index.js"; | ||
import sbp from '@sbp/sbp' | ||
import assert from 'node:assert/strict' | ||
import { describe, it, mock } from 'node:test' | ||
import '../dist/esm/index.js' | ||
|
||
describe("[SBP] EVENTS domain", () => { | ||
it("should register event listener", () => { | ||
const testListener = mock.fn(() => {}); | ||
sbp("okTurtles.events/on", "testEvent", testListener); | ||
sbp("okTurtles.events/emit", "testEvent"); | ||
sbp("okTurtles.events/emit", "testEvent"); | ||
assert.equal(testListener.mock.callCount(), 2); | ||
}); | ||
it("should pass event listener the right data", () => { | ||
const testListener = mock.fn(() => {}); | ||
const testData = 1; | ||
sbp("okTurtles.events/on", "testEvent", testListener); | ||
sbp("okTurtles.events/emit", "testEvent", testData); | ||
assert.equal(testListener.mock.callCount(), 1); | ||
assert.deepEqual(testListener.mock.calls[0].arguments, [testData]); | ||
}); | ||
describe('[SBP] EVENTS domain', () => { | ||
it('should register event listener', () => { | ||
const testListener = mock.fn(() => {}) | ||
sbp('okTurtles.events/on', 'testEvent', testListener) | ||
sbp('okTurtles.events/emit', 'testEvent') | ||
sbp('okTurtles.events/emit', 'testEvent') | ||
assert.equal(testListener.mock.callCount(), 2) | ||
}) | ||
it('should pass event listener the right data', () => { | ||
const testListener = mock.fn(() => {}) | ||
const testData = 1 | ||
sbp('okTurtles.events/on', 'testEvent', testListener) | ||
sbp('okTurtles.events/emit', 'testEvent', testData) | ||
assert.equal(testListener.mock.callCount(), 1) | ||
assert.deepEqual(testListener.mock.calls[0].arguments, [testData]) | ||
}) | ||
it('should call "once" listener once', () => { | ||
const testListener = mock.fn(() => {}); | ||
sbp("okTurtles.events/once", "testEvent", testListener); | ||
sbp("okTurtles.events/emit", "testEvent"); | ||
sbp("okTurtles.events/emit", "testEvent"); | ||
assert.equal(testListener.mock.callCount(), 1); | ||
}); | ||
it("should disable listener correctly", () => { | ||
const testListener = mock.fn(() => {}); | ||
sbp("okTurtles.events/on", "testEvent2", testListener); | ||
sbp("okTurtles.events/emit", "testEvent2"); | ||
sbp("okTurtles.events/off", "testEvent2"); | ||
sbp("okTurtles.events/emit", "testEvent2"); | ||
assert.equal(testListener.mock.callCount(), 1); | ||
}); | ||
it("should disable listener correctly (using return value)", () => { | ||
const testListener = mock.fn(() => {}); | ||
const disable = sbp("okTurtles.events/on", "testEvent2", testListener); | ||
sbp("okTurtles.events/emit", "testEvent2"); | ||
disable(); | ||
sbp("okTurtles.events/emit", "testEvent2"); | ||
assert.equal(testListener.mock.callCount(), 1); | ||
}); | ||
it("should return cleanup function from on", () => { | ||
const testListener = mock.fn(() => {}); | ||
const cleanup = sbp("okTurtles.events/on", "testEvent", testListener); | ||
assert.equal(typeof cleanup, "function"); | ||
sbp("okTurtles.events/emit", "testEvent"); | ||
cleanup(); | ||
sbp("okTurtles.events/emit", "testEvent"); | ||
assert.equal(testListener.mock.callCount(), 1); | ||
}); | ||
it("should return cleanup function from once", () => { | ||
const testListener = mock.fn(() => {}); | ||
const cleanup = sbp("okTurtles.events/once", "testEvent", testListener); | ||
assert.equal(typeof cleanup, "function"); | ||
cleanup(); | ||
sbp("okTurtles.events/emit", "testEvent"); | ||
assert.equal(testListener.mock.callCount(), 0); | ||
}); | ||
}); | ||
const testListener = mock.fn(() => {}) | ||
sbp('okTurtles.events/once', 'testEvent', testListener) | ||
sbp('okTurtles.events/emit', 'testEvent') | ||
sbp('okTurtles.events/emit', 'testEvent') | ||
assert.equal(testListener.mock.callCount(), 1) | ||
}) | ||
it('should disable listener correctly', () => { | ||
const testListener = mock.fn(() => {}) | ||
sbp('okTurtles.events/on', 'testEvent2', testListener) | ||
sbp('okTurtles.events/emit', 'testEvent2') | ||
sbp('okTurtles.events/off', 'testEvent2') | ||
sbp('okTurtles.events/emit', 'testEvent2') | ||
assert.equal(testListener.mock.callCount(), 1) | ||
}) | ||
it('should disable listener correctly (using return value)', () => { | ||
const testListener = mock.fn(() => {}) | ||
const disable = sbp('okTurtles.events/on', 'testEvent2', testListener) | ||
sbp('okTurtles.events/emit', 'testEvent2') | ||
disable() | ||
sbp('okTurtles.events/emit', 'testEvent2') | ||
assert.equal(testListener.mock.callCount(), 1) | ||
}) | ||
it('should return cleanup function from on', () => { | ||
const testListener = mock.fn(() => {}) | ||
const cleanup = sbp('okTurtles.events/on', 'testEvent', testListener) | ||
assert.equal(typeof cleanup, 'function') | ||
sbp('okTurtles.events/emit', 'testEvent') | ||
cleanup() | ||
sbp('okTurtles.events/emit', 'testEvent') | ||
assert.equal(testListener.mock.callCount(), 1) | ||
}) | ||
it('should return cleanup function from once', () => { | ||
const testListener = mock.fn(() => {}) | ||
const cleanup = sbp('okTurtles.events/once', 'testEvent', testListener) | ||
assert.equal(typeof cleanup, 'function') | ||
cleanup() | ||
sbp('okTurtles.events/emit', 'testEvent') | ||
assert.equal(testListener.mock.callCount(), 0) | ||
}) | ||
}) |