Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
64 lines (56 loc) · 2.24 KB

File metadata and controls

64 lines (56 loc) · 2.24 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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))
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.