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
55 lines (47 loc) · 1.7 KB

File metadata and controls

55 lines (47 loc) · 1.7 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
import XCTest
@testable import JavaScriptKit
final class JSTimerTests: XCTestCase {
func testOneshotTimerCancelled() {
let timeoutMilliseconds = 5.0
var timeout: JSTimer!
timeout = JSTimer(millisecondsDelay: timeoutMilliseconds, isRepeating: false) {
XCTFail("timer should be cancelled")
}
_ = timeout
timeout = nil
}
func testRepeatingTimerCancelled() async throws {
var count = 0.0
let maxCount = 5.0
var interval: JSTimer?
let start = JSDate().valueOf()
let timeoutMilliseconds = 5.0
await withCheckedContinuation { continuation in
interval = JSTimer(millisecondsDelay: 5, isRepeating: true) {
// ensure that JSTimer is living
XCTAssertNotNil(interval)
// verify that at least `timeoutMilliseconds * count` passed since the `timeout`
// timer started
XCTAssertTrue(start + timeoutMilliseconds * count <= JSDate().valueOf())
guard count < maxCount else {
// stop the timer after `maxCount` reached
interval = nil
continuation.resume()
return
}
count += 1
}
}
withExtendedLifetime(interval) {}
}
func testTimer() async throws {
let timeoutMilliseconds = 5.0
var timeout: JSTimer!
await withCheckedContinuation { continuation in
timeout = JSTimer(millisecondsDelay: timeoutMilliseconds, isRepeating: false) {
continuation.resume()
}
}
withExtendedLifetime(timeout) {}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.