| function shouldBe(actual, expected) { |
| if (actual !== expected) |
| throw new Error(`expected ${expected} but got ${actual}`); |
| } |
| |
| function shouldBeOneOf(actual, expectedArray) { |
| if (!expectedArray.some((value) => value === actual)) |
| throw new Error('bad value: ' + actual + ' expected values: ' + expectedArray); |
| } |
| |
| function shouldNotThrow(func) { |
| func(); |
| } |
| |
| function shouldThrow(func, errorType) { |
| let error; |
| try { |
| func(); |
| } catch (e) { |
| error = e; |
| } |
| |
| if (!(error instanceof errorType)) |
| throw new Error(`Expected ${errorType.name}!`); |
| } |
| |
| if (Intl.DurationFormat) { |
| shouldBe(new Intl.DurationFormat("fr-FR", { style: "long" }).format({ |
| hours: 1, |
| minutes: 46, |
| seconds: 40, |
| }), `1 heure, 46 minutes et 40 secondes`); |
| } |