Skip to content

Commit

Permalink
fix(core): handle setting falsy value in proxy providers (#118)
Browse files Browse the repository at this point in the history
* fix(proxy-provider-manager): handle setting falsy value

Co-authored-by: Jerry Laloan <jerrylaloan@users.noreply.github.com>
  • Loading branch information
alexandre-abrioux and jerrylaloan authored Jan 31, 2024
1 parent 1bc5e99 commit 26737d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ProxyProviderManager {
return getProvider()[prop];
},
set(_, prop, value) {
return (getProvider()[prop] = value);
return Reflect.set(getProvider(), prop, value);
},
ownKeys() {
return Reflect.ownKeys(getProvider());
Expand Down
23 changes: 23 additions & 0 deletions packages/core/test/proxy-providers/proxy-providers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
ProxyResult,
ProxyResults,
} from './expect-ids-proxy';
import { globalClsService } from '../../src/lib/cls-service.globals';
import { ProxyProviderManager } from '../../src/lib/proxy-provider';

@Injectable()
class InjectedClass {
Expand Down Expand Up @@ -142,3 +144,24 @@ describe('Proxy providers', () => {
await expectOkIdsProxy(app);
});
});

describe('Edge cases', () => {
it('proxy should allow setting falsy value', async () => {
const clsService = globalClsService;
const symbol = Symbol('testSymbol');
const proxyProvider = ProxyProviderManager.createProxyProvider({
provide: symbol,
type: 'object',
useFactory: () => ({
booleanTest: true,
}),
});
const proxy = proxyProvider.useFactory();
await clsService.run(async () => {
await ProxyProviderManager.resolveProxyProviders();
expect(proxy.booleanTest).toBe(true);
proxy.booleanTest = false;
expect(proxy.booleanTest).toBe(false);
});
});
});

0 comments on commit 26737d8

Please sign in to comment.