GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — JavaScriptKit/Tests/JavaScriptKitTests/JSExceptionTests.swift at main · t089/JavaScriptKit Expand file tree/ Copy pathJSExceptionTests.swiftMore file actions 64 lines (56 loc) · 2.24 KB / Copy pathJSExceptionTests.swiftFile metadata and controls64 lines (56 loc) · 2.24 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 import XCTest import JavaScriptKit class JSExceptionTests: XCTestCase { private func eval(_ code: String) -> JSValue { return JSObject.global.eval!(code) } func testThrowingMethodCalls() { let context = eval( """ (() => ({ func1: () => { throw new Error(); }, func2: () => { throw 'String Error'; }, func3: () => { throw 3.0; }, }))() """ ).object! // MARK: Throwing method calls XCTAssertThrowsError(try context.throwing.func1!()) { error in XCTAssertTrue(error is JSException) let errorObject = JSError(from: (error as! JSException).thrownValue) XCTAssertNotNil(errorObject) } XCTAssertThrowsError(try context.throwing.func2!()) { error in XCTAssertTrue(error is JSException) let thrownValue = (error as! JSException).thrownValue XCTAssertEqual(thrownValue.string, "String Error") } XCTAssertThrowsError(try context.throwing.func3!()) { error in XCTAssertTrue(error is JSException) let thrownValue = (error as! JSException).thrownValue XCTAssertEqual(thrownValue.number, 3.0) } } func testThrowingUnboundFunctionCalls() { let jsThrowError = eval("() => { throw new Error(); }") XCTAssertThrowsError(try jsThrowError.function!.throws()) { error in XCTAssertTrue(error is JSException) let errorObject = JSError(from: (error as! JSException).thrownValue) XCTAssertNotNil(errorObject) } } func testThrowingConstructorCalls() { let Animal = JSObject.global.Animal.function! XCTAssertNoThrow(try Animal.throws.new("Tama", 3, true)) XCTAssertThrowsError(try Animal.throws.new("Tama", -3, true)) { error in XCTAssertTrue(error is JSException) let errorObject = JSError(from: (error as! JSException).thrownValue) XCTAssertNotNil(errorObject) } } func testInitWithMessage() { let message = "THIS IS AN ERROR MESSAGE" let exception = JSException(message: message) XCTAssertTrue(exception.description.contains(message)) } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |