Skip to content

Commit 3da1447

Browse files
committed
Add Context util tests
1 parent 9e37ad1 commit 3da1447

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

packages/collaboration-manager/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"clear": "rm -rf ./dist && rm -rf ./tsconfig.build.tsbuildinfo"
1818
},
1919
"dependencies": {
20-
"@editorjs/model": "workspace:^"
20+
"@editorjs/model": "workspace:^",
21+
"@editorjs/sdk": "workspace:^"
2122
},
2223
"devDependencies": {
2324
"@jest/globals": "^29.7.0",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { getContext, runWithContext, WithContext } from './Context.js';
2+
3+
describe('Context util', () => {
4+
it('should run function in context', () => {
5+
const func = (): string | undefined => {
6+
return getContext<string>();
7+
};
8+
9+
expect(runWithContext('context', func)).toEqual('context');
10+
});
11+
12+
it('should run several functions in context respectively', () => {
13+
const func = (): string | undefined => {
14+
return getContext<string>();
15+
};
16+
17+
const result1 = runWithContext('context1', func);
18+
const result2 = runWithContext('context2', func);
19+
20+
expect(result1).toEqual('context1');
21+
expect(result2).toEqual('context2');
22+
});
23+
24+
it('should run method in context', () => {
25+
// eslint-disable-next-line jsdoc/require-jsdoc
26+
class Test {
27+
@WithContext
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars,jsdoc/require-jsdoc
29+
public method(_context: string): string | undefined {
30+
return getContext<string>();
31+
}
32+
}
33+
34+
const instance = new Test();
35+
36+
expect(instance.method('context')).toEqual('context');
37+
});
38+
});

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ __metadata:
645645
resolution: "@editorjs/collaboration-manager@workspace:packages/collaboration-manager"
646646
dependencies:
647647
"@editorjs/model": "workspace:^"
648+
"@editorjs/sdk": "workspace:^"
648649
"@jest/globals": "npm:^29.7.0"
649650
"@stryker-mutator/core": "npm:^7.0.2"
650651
"@stryker-mutator/jest-runner": "npm:^7.0.2"

0 commit comments

Comments
 (0)