| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e9ac468 commit 968b867
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -251,6 +251,8 @@ are recursively evaluated also by the following rules. | |||
| 251 | 251 | * Map keys and Set items are compared unordered. | |
| 252 | 252 | * Recursion stops when both sides differ or both sides encounter a circular | |
| 253 | 253 | reference. | |
| 254 | + * [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. See | ||
| 255 | + below for further details. | ||
| 254 | 256 | ||
| 255 | 257 | ```js | |
| 256 | 258 | const assert = require('assert').strict; | |
@@ -292,6 +294,16 @@ assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 }); | |||
| 292 | 294 | // OK, because it is the same symbol on both objects. | |
| 293 | 295 | assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 }); | |
| 294 | 296 | // Fails because symbol1 !== symbol2! | |
| 297 | + | ||
| 298 | + const weakMap1 = new WeakMap(); | ||
| 299 | + const weakMap2 = new WeakMap([[{}, {}]]); | ||
| 300 | + const weakMap3 = new WeakMap(); | ||
| 301 | + weakMap3.unequal = true; | ||
| 302 | + | ||
| 303 | + assert.deepStrictEqual(weakMap1, weakMap2); | ||
| 304 | + // OK, because it is impossible to compare the entries | ||
| 305 | + assert.deepStrictEqual(weakMap1, weakMap3); | ||
| 306 | + // Fails because weakMap3 has a property that weakMap1 does not contain! | ||
| 295 | 307 | ``` | |
| 296 | 308 | ||
| 297 | 309 | If the values are not equal, an `AssertionError` is thrown with a `message` | |
@@ -893,6 +905,8 @@ For more information, see | |||
| 893 | 905 | [`Set`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set | |
| 894 | 906 | [`Symbol`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol | |
| 895 | 907 | [`TypeError`]: errors.html#errors_class_typeerror | |
| 908 | + [`WeakMap`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/WeakMap | ||
| 909 | + [`WeakSet`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/WeakSet | ||
| 896 | 910 | [`assert.deepEqual()`]: #assert_assert_deepequal_actual_expected_message | |
| 897 | 911 | [`assert.deepStrictEqual()`]: #assert_assert_deepstrictequal_actual_expected_message | |
| 898 | 912 | [`assert.notDeepStrictEqual()`]: #assert_assert_notdeepstrictequal_actual_expected_message | |
| Back | FazBrowse Home | New Git URL |
0 commit comments