diff options
| author | Shinigami <[email protected]> | 2023-07-18 07:23:26 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-18 05:23:26 +0000 |
| commit | 5f947cbd4773f768a90243e54fd707c9769e8530 (patch) | |
| tree | 6fa92071b458fc6a56e7e2f09ed99c07e504ffb8 /test | |
| parent | a3a1480cb3ad9301b4e5e53ba8a281d1e170bca5 (diff) | |
| download | faker-5f947cbd4773f768a90243e54fd707c9769e8530.tar.xz faker-5f947cbd4773f768a90243e54fd707c9769e8530.zip | |
chore: enable strictBindCallApply (#2254)
Diffstat (limited to 'test')
| -rw-r--r-- | test/internal/bind-this-to-member-functions.spec.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/internal/bind-this-to-member-functions.spec.ts b/test/internal/bind-this-to-member-functions.spec.ts new file mode 100644 index 00000000..7dedc00e --- /dev/null +++ b/test/internal/bind-this-to-member-functions.spec.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from 'vitest'; +import type { Faker } from '../../src'; +import { faker } from '../../src'; +import { bindThisToMemberFunctions } from '../../src/internal/bind-this-to-member-functions'; + +describe('internal', () => { + describe('bind-this-to-member-functions', () => { + it('should bind this to member functions', () => { + class SomeModule { + constructor(private readonly faker: Faker) {} + + someMethod(): number { + return this.faker.number.int(); + } + } + + const someModule = new SomeModule(faker); + + const someMethodWithoutBind = someModule.someMethod; + + // The second error message is for NodeJS v14 support + expect(() => someMethodWithoutBind()).toThrow( + /^(Cannot read properties of undefined \(reading 'faker'\)|Cannot read property 'faker' of undefined)$/ + ); + + bindThisToMemberFunctions(someModule); + + const someMethod = someModule.someMethod; + + expect(() => someMethod()).not.toThrow(); + }); + }); +}); |
