@@ -321,6 +321,52 @@ describe(module.id, function () {
321321 JSApi . new ( ) . methodError ( 1 ) ;
322322 } ) . toThrowError ( / J S e r r o r / ) ;
323323 } ) ;
324+ it ( "throws JS Error wrapping NSError when no error arg is passed" , function ( ) {
325+ var isThrown = false ;
326+ try {
327+ // TNSApi.methodError(errorCode, error: NSError**)
328+ // Calling without the last interop.Reference should cause the runtime to
329+ // throw a JS Error that wraps the native NSError (for non-zero errorCode).
330+ TNSApi . new ( ) . methodError ( 1 ) ;
331+ } catch ( e ) {
332+ isThrown = true ;
333+
334+ // Basic shape checks
335+ expect ( e ) . toBeDefined ( ) ;
336+ expect ( e . message ) . toEqual ( jasmine . any ( String ) ) ;
337+ expect ( e . stack ) . toEqual ( jasmine . any ( String ) ) ; // proper JS stack present
338+
339+ // Fields we attach from the NSError
340+ expect ( e . code ) . toBe ( 1 ) ;
341+ expect ( e . domain ) . toBe ( "TNSErrorDomain" ) ;
342+
343+ // nativeException should be the wrapped NSError object
344+ expect ( e . nativeException ) . toBeDefined ( ) ;
345+ // The wrapped object should behave like an NSError proxy/wrapper
346+ // (we assert existence of localizedDescription property)
347+ expect ( typeof e . nativeException . localizedDescription ) . toBe ( 'string' ) ;
348+ } finally {
349+ expect ( isThrown ) . toBe ( true ) ;
350+ }
351+ } ) ;
352+
353+ it ( "does not throw when error arg is passed and the error ref is filled" , function ( ) {
354+ // When the caller passes an interop.Reference() as the last argument,
355+ // the runtime should not throw; it should return the method's boolean
356+ // result and write the NSError into the reference.
357+ var errorRef = new interop . Reference ( ) ;
358+ var result = TNSApi . new ( ) . methodError ( 1 , errorRef ) ;
359+
360+ // The method returns false for non-zero error code
361+ expect ( result ) . toBe ( false ) ;
362+
363+ // The errorRef should be populated with an NSError
364+ expect ( errorRef . value instanceof NSError ) . toBe ( true ) ;
365+
366+ // Validate the NSError contents
367+ expect ( errorRef . value . code ) . toBe ( 1 ) ;
368+ expect ( errorRef . value . domain ) . toBe ( "TNSErrorDomain" ) ;
369+ } ) ;
324370
325371// it("NSErrorExpose", function () {
326372// var JSApi = TNSApi.extend({
0 commit comments