Skip to content

Commit b6a6a77

Browse files
committed
fix: Use count for the specific invocation
1 parent e1fc069 commit b6a6a77

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad
3434

3535
By [@linkdotnet](https://github.com/linkdotnet) and [@egil](https://github.com/egil).
3636

37+
### Fixed
38+
39+
- `JSInterop.VerifyInvoke` reported the wrong number of actual invocations of a given identifier. Reported by [@otori](https://github.com/otori). Fixed by [@linkdotnet](https://github.com/linkdotnet).
40+
3741
## [1.9.8] - 2022-06-07
3842

3943
### Changed

src/bunit.web/Asserting/JSRuntimeAssertExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static IReadOnlyList<JSRuntimeInvocation> VerifyInvoke(JSRuntimeInvocati
114114

115115
if (invocations.Count != calledTimes)
116116
{
117-
throw new JSInvokeCountExpectedException(identifier, calledTimes, allInvocations.Count, nameof(VerifyInvoke), userMessage);
117+
throw new JSInvokeCountExpectedException(identifier, calledTimes, invocations.Count, nameof(VerifyInvoke), userMessage);
118118
}
119119

120120
return invocations;

tests/bunit.web.tests/Asserting/JSRuntimeAssertExtensionsTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,20 @@ public async Task Test308()
210210
var invocation = handler.VerifyInvoke(identifier);
211211
invocation.ShouldBe(handler.Invocations[identifier][0]);
212212
}
213-
}
213+
214+
[Fact(DisplayName = "JSRuntimeInvocationHandler.VerifyInvoke reports the actual and expected amount")]
215+
public async Task Test309()
216+
{
217+
var sut = CreateSut();
218+
const string identifier = "test";
219+
const string unrelatedIdentifier = "not a test";
220+
var handler = sut.SetupVoid().SetVoidResult();
221+
await sut.JSRuntime.InvokeVoidAsync(unrelatedIdentifier);
222+
223+
await sut.JSRuntime.InvokeVoidAsync(identifier);
224+
225+
var actual = Should.Throw<JSInvokeCountExpectedException>(() => handler.VerifyInvoke(identifier, 2));
226+
actual.Message.ShouldContain("Expected number of calls: 2");
227+
actual.Message.ShouldContain("Actual number of calls: 1");
228+
}
229+
}

0 commit comments

Comments
 (0)