Accept constructor in "an" for matching custom types
See original GitHub issueInstead of just accepting a string, it’d be nice if “a” and “an” would accept a constructor to test if an object inherits from another.
// es5
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
// es6
class Bar extends Foo {}
// assertion
expect(Bar).to.be.a(Foo);
Bar.prototype instanceof Object; // true
Bar.prototype instanceof Foo; // true
Bar.prototype instanceof Baz; // false
Issue Analytics
- State:
- Created 9 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
haskell - Can you pattern match constructors on a type class ...
Pattern matching deconstructs a concrete data type. You choose one specific type, and look at its constructors. That means your code can no ......
Read more >Java Method/Constructor in Class Cannot be Applied to Given ...
Java "Method/Constructor in Class Cannot Be Applied To Given Types" happens when formal parameters and the actual parameters differ.
Read more >Type declarations and pattern matching - The Caml language
Constructors can have arguments. The keyword of indicates the type of the constructor's arguments. This supports the gathering into a single type of...
Read more >Data Types and Matching · OCaml Tutorials
In this tutorial, we will define our own compound data types, using the type keyword, and some of these built-in structures as building...
Read more >Writing a constructor in TypeScript - LogRocket Blog
By instance type method, we're referring to a “normal” function that would be called with obj.funcCall() existing on the object instance, as a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @thejameskyle that sounds like a great idea! Of course, for now, you can use
instanceof
(e.g.expect(Bar).to.be.an.instanceof(Foo)
: http://chaijs.com/api/bdd/#instanceof-section). But yes,a
andan
could definitely support this too. If you’d like to formulate a PR, with tests and documentation, then I’d look to merging it.Clearing out old issues, closing for inactivity