Environment
What do you want to do
Current State Example
//src/main.ts
namespace base {
export class Foo {
constructor() { console.log("Called Foo Constructor!");}
public answerToTheUltimateQuestion(): number {return42;}
public callHello() {return new Bar().say()}
}
}
// src/Hello.ts
namespace base {
export class Bar {
constructor() { console.log("Called Bar Constructor!";};
say():string {return "hello!";}
getFoo() {return new base.Foo();}
}
}
// \__tests__/main.test.ts
const foo = new base.Foo(); // ReferenceError: base is not defined
test("someMethod",()=>{
expect(foo.answerToTheUltimateQuestion()) .toBe(42);
});
Environment
What you want to do
Current State Example
//src/main.ts
namespace base {
export class Foo {
constructor() { console.log("Called Foo Constructor!");}
public answerToTheUltimateQuestion(): number {return42;}
public callHello() {return new Bar().say()}
}
}
// src/Hello.ts
namespace base {
export class Bar {
constructor() { console.log("Called Bar Constructor!";};
say():string {return "hello!";}
getFoo() {return new base.Foo();}
}
}
// \__tests__/main.test.ts
const foo = new base.Foo(); // ReferenceError: base is not defined
test("someMethod",()=>{
expect(foo.answerToTheUltimateQuestion()) .toBe(42);
});
I know it's best to rewrite it in a modular format, but it has a large number of files and
It's hard to change, so I'll do my best to test it.
I want to re-write it after securing a situation where I can understand even if it is broken.
Is it possible to change the d.ts file, change the target of tconfig.json, or resolve it by any other means?
There was a similar question in our stackoverflow.However, our questions have not been solved.
How would I test typecode that uses names in Node.js?
However, there was an introduction to using the TypeScript --outFile
option.
//<reference/>
with the dependent file path in the test code as follows:
outFile
option with main.test.js
and so on.
A single test code and dependency code can be combined to correct the test code and
You may be able to do this with just the ingenuity of the build tool.
//\_tests__/main.test.ts
/// <reference path="main.ts"/>
/// <reference path="Hello.ts"/>
const foo = new base.Foo(); // ReferenceError: base is not defined
test("someMethod",()=>{
expect(foo.answerToTheUltimateQuestion()) .toBe(42);
});
© 2024 OneMinuteCode. All rights reserved.