I've searched through previous posts for an answer, but haven't come across one yet. Here is my query:
Currently, I am attempting to test the returned type of a property value in an Object instance using Chai's expect() method in Typescript. This is what I have tried so far:
/* My type file */
export type customType = "one" | "two" | "three";
export default customType;
/* My test file */
import customType from '{path_to_customType}'; // 'customType' is declared but not used.
const newObject = new Object({property1: value1}) //note: value1 has a type of customType
describe("Class1 test", () => {
it('my tests', () => {
expect(newObject).to.have.property("property1").to.equal("value1"); // this assertion works fine
expect(newObject).to.be.a('customType'); // not working
expect(newObject).to.be.an('customType'); // not working
expect(newObject).to.be.a(customType); // not working
expect(newObject).to.be.an(customType); // not working
expect(typeof newObject.getProperty1()).to.equal('customType'); // not working
expect(newObject).to.be.an.instanceof(customType); // not working
expect(newObject).to.be.an.instanceof('customType'); // not working
assert.typeOf(newObject.getProperty1(), 'customType'); // not working
assert.typeOf(newObject.getProperty1(), customType); // not working
});
});
As observed, value1
should be of type customType
, however, I receive an error as customType
is not being read.
How can I accurately determine if my value matches a specific custom type?
**Note: In the Object definition, the property property1
is specified as type customType
*UPDATE Upon further investigation, I noticed that the returned type of value1
is 'string', indicating that the type is simply an alias... How do I go about testing this now?