File tree Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 1+ unreleased :
2+ new features :
3+ - GH-1369 Added `isEvent` method in Event class
4+
154.4.1 :
26 date : 2024-07-29
37 fixed bugs :
Original file line number Diff line number Diff line change @@ -87,7 +87,18 @@ _.assign(Event, /** @lends Event */ {
8787 * @readOnly
8888 * @type {String }
8989 */
90- _postman_propertyName : 'Event'
90+ _postman_propertyName : 'Event' ,
91+
92+ /**
93+ * Check whether an object is an instance of {@link Event}.
94+ *
95+ * @param {* } obj -
96+ * @returns {Boolean }
97+ */
98+ isEvent : function isPostmanEvent ( obj ) {
99+ return Boolean ( obj ) && ( ( obj instanceof Event ) ||
100+ _ . inSuperChain ( obj . constructor , '_postman_propertyName' , Event . _postman_propertyName ) ) ;
101+ }
91102} ) ;
92103
93104module . exports = {
Original file line number Diff line number Diff line change @@ -168,4 +168,27 @@ describe('Event', function () {
168168 expect ( afterJSON . script ) . to . not . have . property ( 'packages' ) ;
169169 } ) ;
170170 } ) ;
171+
172+ describe ( 'isEvent' , function ( ) {
173+ var rawEvent = {
174+ listen : 'test' ,
175+ id : 'my-global-script-1' ,
176+ script : {
177+ type : 'text/javascript' ,
178+ exec : 'console.log("hello");'
179+ }
180+ } ;
181+
182+ it ( 'should return true for an Event instance' , function ( ) {
183+ expect ( Event . isEvent ( new Event ( rawEvent ) ) ) . to . be . true ;
184+ } ) ;
185+
186+ it ( 'should return false for a raw Event object' , function ( ) {
187+ expect ( Event . isEvent ( rawEvent ) ) . to . be . false ;
188+ } ) ;
189+
190+ it ( 'should return false when called without arguments' , function ( ) {
191+ expect ( Event . isEvent ( ) ) . to . be . false ;
192+ } ) ;
193+ } ) ;
171194} ) ;
Original file line number Diff line number Diff line change 1- // Type definitions for postman-collection 4.4.0
1+ // Type definitions for postman-collection 4.4.1
22// Project: https://github.com/postmanlabs/postman-collection
33// Definitions by: PostmanLabs
44// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -649,6 +649,11 @@ declare module "postman-collection" {
649649 * The script that is to be executed when this event is triggered.
650650 */
651651 script : Script ;
652+ /**
653+ * Check whether an object is an instance of Event.
654+ * @param obj - -
655+ */
656+ static isEvent ( obj : any ) : boolean ;
652657 }
653658
654659 export namespace FormParam {
You can’t perform that action at this time.
0 commit comments