Skip to content

Commit

Permalink
Merge branch 'main' into vkukreja/doc-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 29, 2023
2 parents bfc995a + e21916d commit da57dc2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/aws-cdk-lib/core/lib/cfn-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CfnCondition } from './cfn-condition';
/* eslint-disable import/order */
import { CfnRefElement } from './cfn-element';
import { CfnCreationPolicy, CfnDeletionPolicy, CfnUpdatePolicy } from './cfn-resource-policy';
import { Construct, IConstruct, Node } from 'constructs';
import { Construct, Node } from 'constructs';
import { addDependency, obtainDependencies, removeDependency } from './deps';
import { CfnReference } from './private/cfn-reference';
import { Reference } from './reference';
Expand Down Expand Up @@ -34,10 +34,10 @@ export interface CfnResourceProps {
*/
export class CfnResource extends CfnRefElement {
/**
* Check whether the given construct is a CfnResource
* Check whether the given object is a CfnResource
*/
public static isCfnResource(construct: IConstruct): construct is CfnResource {
return (construct as any).cfnResourceType !== undefined;
public static isCfnResource(x: any): x is CfnResource {
return x !== null && typeof(x) === 'object' && x.cfnResourceType !== undefined;
}

// MAINTAINERS NOTE: this class serves as the base class for the generated L1
Expand Down
24 changes: 24 additions & 0 deletions packages/aws-cdk-lib/core/test/cfn-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,28 @@ describe('cfn resource', () => {
delete process.env.CDK_DEBUG;
}
});

test('isCfnResource returns true with a CfnResource', () => {
const app = new core.App();
const stack = new core.Stack(app, 'Stack');
const res = new core.CfnResource(stack, 'SomeCfnResource', {
type: 'Some::Resource',
});

// THEN
expect(core.CfnResource.isCfnResource(res)).toBe(true);
});

test('isCfnResource returns false with a construct', () => {
const app = new core.App();
const stack = new core.Stack(app, 'Stack');

// THEN
expect(core.CfnResource.isCfnResource(stack)).toBe(false);
});

test('isCfnResource returns false with undefined', () => {
// THEN
expect(core.CfnResource.isCfnResource(undefined)).toBe(false);
});
});

0 comments on commit da57dc2

Please sign in to comment.