0

I am trying to test class "a" (which inherits from class "b") with jest. The typescript compiler prepends the file compiled javascript of "a" with

var __extends = this.__extends || function (d, b) { ... };

unfortunately this is null, when running the unit test, so I am getting

Cannot read property '__extends' of null

I am using [email protected] to run the tests and [email protected] to compile my typescript files. Normally this would point to window, when the files are run in a browser.

Does someone know how to get around that issue?

2 Answers 2

1

This error is not that __extends is null, it describes one of two scenarios.

Either you have forgotten to include the file that contains the base class, or you have included it after the file that contains the sub class.

Practical example:

<!-- Base class first -->
<script src="b.js"></script>
<!-- Now the sub class -->
<script src="a.js"></script>
<!-- Now things that depend on the sub class -->
<script src="tests.js"></script>

If you did this in any other order, you'd get a problem.

If you are compiling to a single file, you'll need to make sure your reference comments are in order to ensure the classes appear in the correct order in the combined file.

Sign up to request clarification or add additional context in comments.

1 Comment

I think the issue is actually that jest is calling the test function using apply(null, args). The error message indicates that this is null (why jest would do that, I have no idea... {} seems like a better choice)
0

This error is the most common error I see when require.js isn't set up properly. Was requirejs properly loaded/configured?

Nathan

2 Comments

this is an issue with jest ... jest is setting up it's own require function
Sorry, wasn't careful enough in my reading... thought I could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.