xxxxxxxxxx
if (typeof me.onChange !== "undefined") {
// safe to use the function me.onChange()
}
//or better yet
if (typeof me.onChange === "function") {
// safe to use the function me.onChange()
}
xxxxxxxxxx
if(document.getElementById("myElmentID").classList.contains("hidden")){
// I have the 'hidden' class
}
xxxxxxxxxx
const element = document.querySelector("#box");
element.classList.contains("active");
xxxxxxxxxx
element.classList.contains(className);Code language: CSS (css)
xxxxxxxxxx
expect(elem.contains('foo')).toBe(true); //expect elem to contain class foo
// Use above if at least this class is expected to be included.
// If an exact series of classes are expected to be in elem use below
expect(elem).toHaveClass("class1 class2");
xxxxxxxxxx
export const isClass = <T>(value: unknown): value is Constructor<T> => {
return typeof value === "function" && typeof value.prototype === "object";
};
export type Constructor<T> = new (args: unknown[]) => T;