Skip to content

Commit

Permalink
feat!: v0.0.1-dev.7 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Jan 11, 2021
1 parent 6969998 commit 3bfbec4
Show file tree
Hide file tree
Showing 6 changed files with 468 additions and 63 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 0.0.1-dev.7

- **BREAKING** refactor: rename `verify(mock).calls(#member)` to `verify(mock).called(#member)`
- feat: add `any` argument matcher support to `verify` and `calls`
- feat: add `anyThat` argument matcher support to `verify` and `calls`
- feat: support `verify(mock).called(#member).once()`
- feat: support `verify(mock).called(#member).never()`
- feat: improve error messages to include invocation arguments

# 0.0.1-dev.6

- **BREAKING** refactor: use `Symbol` rather than `String`
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ The `MockCat` instance can then be used to stub and verify calls.
// Stub the `sound` method.
when(cat).calls(#sound).thenReturn('meow');
// Verify no interactions have occurred.
verify(cat).called(#sound).never();
// Interact with the mock cat instance.
cat.sound();
// Verify the interaction occurred (with matcher support).
verify(cat).calls(#sound).times(equals(1));
// Verify the interaction occurred.
verify(cat).called(#sound).once();
// Interact with the mock instance again.
cat.sound();
// Verify the interaction occurred twice.
verify(cat).called(#sound).times(2);
```

## Additional Usage
Expand Down Expand Up @@ -73,11 +82,18 @@ when(cat).calls(#likes).withArgs(
expect(cat.likes('fish'), isTrue);
// You can verify the interaction for specific arguments.
verify(cat).calls(#likes).withArgs(
verify(cat).called(#likes).withArgs(
positional: ['fish'],
named: {#isHungry: false},
).times(1);
// You can stub a method using argument matchers: `any` or `anyThat`.
when(cat).calls(#likes).withArgs(
positional: [any],
named: {#isHungry: anyThat(isFalse)},
).thenReturn(true);
expect(cat.likes('fish'), isTrue);
// You can stub a method to throw.
when(cat).calls(#sound).thenThrow(Exception('oops'));
expect(() => cat.sound(), throwsA(isA<Exception>()));
Expand Down
6 changes: 3 additions & 3 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
expect(cat.sound(), 'purr');

// Verify the interaction.
verify(cat).calls(#sound).times(1);
verify(cat).called(#sound).once();

// Stub a method with parameters
when(cat).calls(#likes).withArgs(
Expand All @@ -37,10 +37,10 @@ void main() {
expect(cat.likes('fish'), isTrue);

// Verify the interaction.
verify(cat).calls(#likes).withArgs(
verify(cat).called(#likes).withArgs(
positional: ['fish'],
named: {#isHungry: false},
).times(1);
).once();
});
});
}
Loading

0 comments on commit 3bfbec4

Please sign in to comment.