Testy / TestyTs

✔️ Modern TypeScript testing framework.
http://testy.github.io
ISC License
123 stars 8 forks source link

Enums "Undefined" unless in their own file? #56

Closed ohnv closed 3 years ago

ohnv commented 3 years ago

Is it correct that you will receive a "Cannot read property [x] of undefined" error if referencing an enum in a test file, unless that enum is imported from a file with nothing else in it but that enum?

Consider the following fails:

import { expect, TestSuite, Test } from 'testyts';
import { Log, LogLevel } from "../../services/logger";

@TestSuite()
export class Enum {

    @Test()
    CreateDB() {

        Log("This will fail with error 'Cannot read property LogLevel.Trace of undefined'", LogLevel.Trace);
    }
}

However this works:

import { expect, TestSuite, Test } from 'testyts';
import { Log } from "../../services/logger";
import { LogLevel } from "../../services/logger_util";

@TestSuite()
export class Enum {

    @Test()
    CreateDB() {

        Log("Once split into 2 files, this will run fine.", LogLevel.Trace);
    }
}

I had been searching for a fix for this for some time (since it appears to affect other TS test frameworks as well, including Mocha at least). After trying to copy the .tsconfig and testys.json configs with no success, I finally stumbled upon the answer by looking here.

It seems that this is a limitation of TS itself (Please tell me if it's otherwise), so I'm not sure if this is something you can 'fix'. Perhaps a note in the documentation somewhere? Otherwise perhaps this issue itself will help others if they do a search for 'enum' like I tried.

Anyway, really like what you've done. Keep up the good work :-)

Aboisier commented 3 years ago

That's an interesting case! I haven't encountered it, but I'll take a look at this and try and make a repro and either fix it or improve the documentation! Thanks :)

Aboisier commented 3 years ago

Hi @TheTrainor , I haven't been able to reproduce your situation. Perhaps we are using different ts configurations. Do you think you could create a repl repro? Here's my attempt.

ohnv commented 3 years ago

Thanks @Aboisier, it's definitely possible that something in my tsconfig was causing problems.

I will check it out as soon as I'm back from holidays and also see if using your tsconfig as shown in the repl fixes my problems. Thanks again!

Aboisier commented 3 years ago

Hi! Have you had the opportunity to test with my tsconfig? I'll close this for now, but feel free to reopen if this is still an issue. :)