MCPcopy
hub / github.com/heroku/react-refetch / typecheckCheck

Function typecheckCheck

test/components/connect.spec.js:1937–1966  ·  view source on GitHub ↗
(name, expectedTypes, typeException = null)

Source from the content-addressed store, hash-verified

1935 }
1936
1937 function typecheckCheck(name, expectedTypes, typeException = null) {
1938 expectedTypes = Array.isArray(expectedTypes) ? expectedTypes : [ expectedTypes ]
1939 typeException = typeException || function (type) {
1940 return regexpify(
1941 `${name} must be ${expectedTypes.length > 1 ? 'one of' : 'a'} ${expectedTypes}. Instead received a ${type}.`
1942 )
1943 }
1944
1945 const checks = {
1946 boolean: [ true, false ],
1947 function: [ Date, () => {} ],
1948 number: [ 1337, 1.37e25, 0.123456789, Math.PI, -42, 0, NaN, Infinity ],
1949 object: [ null, [ 7.2, 'billion' ], new Date(), { obj: 'ect' } ],
1950 string: [ 'string', 'chaîne', '細線', '😀🌂🔗💯🆗' ],
1951 symbol: [ Symbol('hearts'), Symbol(), Symbol.iterator ],
1952 undefined: [ undefined, void 0 ]
1953 }
1954
1955 for (let type in checks) {
1956 let values = checks[type]
1957 if (expectedTypes.some(t => t === type)) { return }
1958 if (expectedTypes.some(t => t === 'plain object with string values') &&
1959 type === 'object') { values = values.slice(0, 3) }
1960
1961 values.forEach(value => {
1962 expect(() => connect.defaults({ [name]: value })())
1963 .toThrow(typeException(type, value))
1964 })
1965 }
1966 }
1967
1968 it('should throw unless a function is given as buildRequest', () => {
1969 typecheckCheck('buildRequest', 'function')

Callers 1

connect.spec.jsFile · 0.85

Calls 1

regexpifyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…