Skip to content

Commit

Permalink
Adding test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarDegas committed Apr 23, 2024
1 parent 743ee9f commit 10ad564
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions Tests/DSBridgeTests/DSBridgeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ final class DSBridgeTests: XCTestCase {
wait(for: expectations)
}

func testCallingNamespaceFromNative() {
let expectations = [XCTestExpectation(), XCTestExpectation()]
webView.call("syncFunctions.returnAsIs", with: [99], thatReturns: Int.self) {
let returned = try! $0.get()
XCTAssert(returned == 99)
expectations[0].fulfill()
}
webView.call("asyncFunctions.adding100", with: [7], thatReturns: Int.self) {
let returned = try! $0.get()
XCTAssert(returned == 107)
expectations[1].fulfill()
}
wait(for: expectations)
}

override func setUp() {
Interface.testInvoked = false
Interface.input = nil
Expand All @@ -87,11 +102,24 @@ final class DSBridgeTests: XCTestCase {
webView.addInterface(interface, by: nil)
webView.evaluateJavaScript(
"""
bridge.register('addValue', function(l, r){
return l + r;
bridge.register('addValue', function(l, r) {
return l + r;
})
bridge.registerAsyn('append', function(arg1, arg2, arg3, respond) {
respond(arg1 + " " + arg2 + " " + arg3);
})
bridge.register("syncFunctions",{
returnAsIs: function(v) {
return v
}
})
bridge.registerAsyn('append', function(arg1, arg2, arg3, responseCallback){
responseCallback(arg1 + " " + arg2 + " " + arg3);
bridge.registerAsyn("asyncFunctions",{
adding100: function(input, respond) {
respond(input + 100)
}
})
"""
) { _, _ in
Expand Down

0 comments on commit 10ad564

Please sign in to comment.