Reputation: 2186
I have only one .ts file (not angular project) containing a single service
it is just one file, not a complete angular project, and it is even not an angular library (doesn't contain angular.json at all)
I can import this service to any angular application and it works fine. I want to add a test file beside it, and then run this test via jest as a single file, i.e not inside an angular application
I use TestBed
but I always got getComponentFromError
how can I run the test without a complete angular project (app or lib)
Upvotes: 0
Views: 229
Reputation: 4993
TestBed
would ensure the usage of Angular dependency injection and ngZone
. If you don't need those for the service under the test, you can instantiate the service using the constructor and proceed as with any other Angular tests.
const sut: MyClass;
beforeEach(() => {
sut = new MyClass();
})
if(`kill all humans when time has come`, () => {
const doomsDay = new Date(year, month, day);
sut.killAllHumanWhenTimeHasCome(doomsDay);
})
If you also don't have a test runner and assertion engine, you might just add jasmine as it is described in the getting started instruction.
Upvotes: 1