-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Zorkaltsev
committed
Apr 5, 2024
1 parent
b7e397d
commit ed1c567
Showing
10 changed files
with
651 additions
and
7 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
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
File renamed without changes.
File renamed without changes.
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
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import {Context} from "../../context/Context"; | ||
import {EnsureContext} from "../../context/ensureContext"; | ||
|
||
describe('ensureContext', () => { | ||
it('positional args', () => { | ||
class Test { | ||
// @ts-ignore | ||
noArgs(): void; | ||
noArgs(ctx: Context): void; | ||
@EnsureContext(true) | ||
noArgs(ctx: Context): void { | ||
expect(ctx instanceof Context).toBeTruthy(); | ||
} | ||
|
||
// @ts-ignore | ||
posArgs(n: number, s: string): void; | ||
posArgs(ctx: Context, n: number, s: string): void; | ||
@EnsureContext(true) | ||
posArgs(ctx: Context, n: number, s: string) { | ||
expect(ctx instanceof Context).toBeTruthy(); | ||
expect(n).toBe(12); | ||
expect(s).toBe('test'); | ||
} | ||
|
||
// @ts-ignore | ||
static staticNoArgs(): void; | ||
static staticNoArgs(ctx: Context): void; | ||
|
||
@EnsureContext(true) | ||
static staticNoArgs(ctx: Context) { | ||
expect(ctx instanceof Context).toBeTruthy(); | ||
} | ||
} | ||
|
||
const test = new Test(); | ||
|
||
test.noArgs(); | ||
test.noArgs(Context.createNew().ctx); | ||
|
||
test.posArgs(12, 'test'); | ||
test.posArgs(Context.createNew().ctx, 12, 'test'); | ||
|
||
Test.staticNoArgs(); | ||
}); | ||
|
||
it('named args', () => { | ||
class Test { | ||
// noArgs(): void; | ||
// noArgs(opts: { | ||
// ctx?: Context, | ||
// }): void; | ||
@EnsureContext() | ||
noArgs(opts?: { | ||
ctx?: Context, | ||
}): void { | ||
const ctx = opts!.ctx!; | ||
expect(ctx instanceof Context).toBeTruthy(); | ||
} | ||
|
||
@EnsureContext(false) // should throw error cause fire arg is not obj | ||
mismatchTypeOfArgs(n: number, s: string) { | ||
expect(n).toBe(12); | ||
expect(s).toBe('test'); | ||
} | ||
} | ||
|
||
const test = new Test(); | ||
|
||
test.noArgs(); | ||
test.noArgs({}); | ||
test.noArgs({ | ||
ctx: Context.createNew().ctx, | ||
}); | ||
|
||
expect(() => test.mismatchTypeOfArgs(12, 'test')).rejects | ||
.toThrow('An object with options or undefined is expected as the first argument'); | ||
}); | ||
}); |
Oops, something went wrong.