(optRaise= undefined, unredacted= false)
| 1809 | * @type {MakeAssert} |
| 1810 | */ |
| 1811 | const makeAssert= (optRaise= undefined, unredacted= false)=> { |
| 1812 | const details= unredacted? unredactedDetails: redactedDetails; |
| 1813 | const assertFailedDetails= details `Check failed`; |
| 1814 | |
| 1815 | /** @type {AssertFail} */ |
| 1816 | const fail= ( |
| 1817 | optDetails= assertFailedDetails, |
| 1818 | ErrorConstructor= globalThis.Error)=> |
| 1819 | { |
| 1820 | const reason= makeError(optDetails, ErrorConstructor); |
| 1821 | if( optRaise!== undefined) { |
| 1822 | optRaise(reason); |
| 1823 | } |
| 1824 | throw reason; |
| 1825 | }; |
| 1826 | freeze(fail); |
| 1827 | |
| 1828 | /** @type {FailTag} */ |
| 1829 | const Fail= (template, ...args)=> fail(details(template, ...args)); |
| 1830 | |
| 1831 | // Don't freeze or export `baseAssert` until we add methods. |
| 1832 | // TODO If I change this from a `function` function to an arrow |
| 1833 | // function, I seem to get type errors from TypeScript. Why? |
| 1834 | /** @type {BaseAssert} */ |
| 1835 | function baseAssert( |
| 1836 | flag, |
| 1837 | optDetails= undefined, |
| 1838 | ErrorConstructor= undefined) |
| 1839 | { |
| 1840 | flag|| fail(optDetails, ErrorConstructor); |
| 1841 | } |
| 1842 | |
| 1843 | /** @type {AssertEqual} */ |
| 1844 | const equal= ( |
| 1845 | actual, |
| 1846 | expected, |
| 1847 | optDetails= undefined, |
| 1848 | ErrorConstructor= undefined)=> |
| 1849 | { |
| 1850 | is(actual, expected)|| |
| 1851 | fail( |
| 1852 | optDetails|| details `Expected ${actual} is same as ${expected}`, |
| 1853 | ErrorConstructor|| RangeError); |
| 1854 | |
| 1855 | }; |
| 1856 | freeze(equal); |
| 1857 | |
| 1858 | /** @type {AssertTypeof} */ |
| 1859 | const assertTypeof= (specimen, typename, optDetails)=> { |
| 1860 | // This will safely fall through if typename is not a string, |
| 1861 | // which is what we want. |
| 1862 | // eslint-disable-next-line valid-typeof |
| 1863 | if( typeof specimen=== typename) { |
| 1864 | return; |
| 1865 | } |
| 1866 | typeof typename=== 'string'|| Fail `${quote(typename)} must be a string`; |
| 1867 | |
| 1868 | if( optDetails=== undefined) { |
no outgoing calls
no test coverage detected