You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/Contributors/TestingGuide/README.md
+16-4Lines changed: 16 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -441,22 +441,34 @@ In addition to testing success cases, we also test all failure cases. The custom
441
441
```javascript
442
442
it("fromDegrees throws with no latitude", function () {
443
443
expect(function () {
444
-
Cartesian3.fromDegrees(0.0);
445
-
}).toThrowDeveloperError();
444
+
Cartesian3.fromDegrees(0.0, undefined);
445
+
}).toThrowDeveloperError(
446
+
"Expected latitude to be typeof number, actual typeof was undefined",
447
+
);
446
448
});
447
449
```
448
450
449
451
Above, `Cartesian3.fromDegrees` is expected to throw a `DeveloperError` because it expects longitude and latitude arguments, and only longitude is provided.
450
452
451
-
Tips:
453
+
#### Tips
454
+
455
+
- When testing for exceptions it is recommended to test for the expected error message to verify that the test is triggering the correct error. This can be achieved either with the full error message, like above, or with a regular expression that will match the error message like this:
456
+
457
+
```javascript
458
+
it("fromDegrees throws with no latitude", function () {
459
+
expect(function () {
460
+
Cartesian3.fromDegrees(0.0, undefined);
461
+
}).toThrowDeveloperError(/Expected latitude to be/);
462
+
});
463
+
```
452
464
453
465
- When testing for exceptions, put only code that is expected to trigger the exception inside the function passed to `expect()`, in case setup code unintentionally throws an exception.
454
466
- To verify the right exception is thrown, it is often useful to comment out the `expect` call when first running the test, for example:
455
467
456
468
```javascript
457
469
it("fromDegrees throws with no latitude", function () {
0 commit comments