question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accept constructor in "an" for matching custom types

See original GitHub issue

Instead 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:closed
  • Created 9 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
keithamuscommented, Dec 11, 2014

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 and an could definitely support this too. If you’d like to formulate a PR, with tests and documentation, then I’d look to merging it.

0reactions
jamiebuildscommented, Jan 8, 2016

Clearing out old issues, closing for inactivity

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found