You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/tests/util/support/types.test.ts

32 lines
866 B

2 years ago
import { expect } from 'chai'
import { isKeyof } from '../../../lib'
describe('util -> support -> types -> isKeyof', () => {
it('should return false for invalid key types', () => {
expect(isKeyof(true, {})).to.be.false
expect(isKeyof(1.5, {})).to.be.false
})
it('should return true if the key is in the object', () => {
const sym = Symbol('test')
const obj = {
foo: true,
[sym]: 123,
}
expect(isKeyof('foo', obj)).to.be.true
expect(isKeyof(sym, obj)).to.be.true
})
it('should return false if the key is not in the object', () => {
const sym = Symbol('test')
const obj = {
foo: true,
[Symbol('test2')]: 123,
}
expect(isKeyof('bar', obj)).to.be.false
expect(isKeyof(sym, obj)).to.be.false
})
})