use vm.expectRevert(Error.custom_error_name.selector):
functiontestCustomError() public { vm.expectRevert(Error.NotAuthorized.selector); err.throwCustomError(); }
Label assertions
If we have a lot of assertions in a test case, Foundry won't tell us which ones succeed and which ones fail. For example:
functiontestErrorLabel() public {assertEq(uint256(1),uint256(1));assertEq(uint256(1),uint256(1));assertEq(uint256(1),uint256(1));assertEq(uint256(1),uint256(2));assertEq(uint256(1),uint256(1)); }
The 4th assertion clearly would fail but Foundry won't tell us the failed one is the 4th assertion. In order to distinguish assertions, we can label them with different names:
// Add label to assertionsfunctiontestErrorLabel() public {assertEq(uint256(1),uint256(1),"test 1");assertEq(uint256(1),uint256(1),"test 2");assertEq(uint256(1),uint256(1),"test 3");assertEq(uint256(1),uint256(2),"test 4");assertEq(uint256(1),uint256(1),"test 5"); }