-
Notifications
You must be signed in to change notification settings - Fork 0
/
aufgabe1.test.mjs
37 lines (31 loc) · 950 Bytes
/
aufgabe1.test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import t from './aufgabe1.mjs'
describe('PubSub std', () => {
const log = console.log;
beforeEach(() => {
console.log = import.meta.jest.fn();
});
afterAll(() => {
console.log = log;
});
test("main", () => {
t.main();
expect(console.log).toHaveBeenNthCalledWith(
1,
expect.stringContaining(`Subscriber1 received Hello!`)
);
expect(console.log).toHaveBeenNthCalledWith(
2,
expect.stringContaining(`Subscriber2 received Hello!`)
);
expect(console.log).toHaveBeenLastCalledWith(
expect.stringContaining(`Subscriber1 received Hello again!`)
);
});
test("unsubscribe", () => {
const bus = t.messageBus();
const id = bus.subscribe(t.subscriber1);
bus.unsubscribe(id);
bus.publish("Hello!");
expect(console.log).not.toHaveBeenCalled();
});
});