Skip to content

Commit fe971a9

Browse files
committed
simplified debounce test adding message counting
1 parent 924549c commit fe971a9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Fabulous.Tests/CmdTests.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ module CmdTestsHelper =
1313
[<TestFixture>]
1414
type ``Cmd tests``() =
1515
[<Test>]
16-
member _.``Cmd.debounce only dispatch the last message``() =
16+
member _.``Cmd.debounce only dispatches the last messages within the timeout``() =
1717
async {
18+
let mutable messageCount = 0
1819
let mutable actualValue = None
1920

2021
let dispatch msg =
21-
if actualValue.IsNone then
22-
actualValue <- Some msg
22+
messageCount <- messageCount + 1
23+
actualValue <- Some msg
2324

2425
let triggerCmd = Cmd.debounce 100 NewValue
2526

@@ -30,14 +31,14 @@ type ``Cmd tests``() =
3031
triggerCmd 3 |> CmdTestsHelper.execute dispatch
3132
do! Async.Sleep 125
3233

34+
Assert.AreEqual(1, messageCount)
3335
Assert.AreEqual(Some(NewValue 3), actualValue)
3436

35-
actualValue <- None
36-
3737
triggerCmd 4 |> CmdTestsHelper.execute dispatch
3838
do! Async.Sleep 75
3939
triggerCmd 5 |> CmdTestsHelper.execute dispatch
4040
do! Async.Sleep 125
4141

42+
Assert.AreEqual(2, messageCount)
4243
Assert.AreEqual(Some(NewValue 5), actualValue)
4344
}

0 commit comments

Comments
 (0)