Flamework TestEZ

Are there any examples of how to test services or controllers? I figure I'd have to use the Dependency macro, but I'm unsure how.
10 Replies
glenacus
glenacusOP3mo ago
I want to do something like this. The first print will work but the second does not.
export = () => {
it("player should load", () => {
print("BBBBBB");
const playerService = Dependency<PlayerService>();
playerService.onPlayerAdded(blah).catch(error);
print("AA");
});
};
export = () => {
it("player should load", () => {
print("BBBBBB");
const playerService = Dependency<PlayerService>();
playerService.onPlayerAdded(blah).catch(error);
print("AA");
});
};
I'm assuming using the Dependency macro is not advised here?
PepeElToro41
PepeElToro413mo ago
I think littensy had an example of jecs running in play mode
glenacus
glenacusOP3mo ago
I looked pretty good I think, most of the repos are Luau or just using Jest w no Flamework.
PepeElToro41
PepeElToro413mo ago
https://github.com/littensy/rbxts-jest-test/blob/main/test/spec.server.lua#L1 Im pretty sure you can just run this in a .server.ts file that's the only way beacuse flamework cant start if the game isnt running
glenacus
glenacusOP3mo ago
Yeah I understand that part I already have the whole system down using TestEZ It's just using the dependency macro inside of the testing export yields infinitely or something. It doesn't throw an error
PepeElToro41
PepeElToro413mo ago
maybe its the environment mocking try printing _G outside and inside tests check if its the same one
glenacus
glenacusOP3mo ago
Mk I'll give it a try ["__TESTEZ_RUNNING_TEST__"] = true Not the same one. When I use the macro outside of the export I get this error upon running the test. Running error for ServerScriptService.TS.tests.player.spec: [string "ReplicatedStorage.rbxts_include.node_modules.@flamework.core.out.modding"]:509: Could not find constructor for server/player/player-service@PlayerService while constructing ArtificialDependency
const playerService = Dependency<PlayerService>(); // Error is from here.

export = () => {
it("player should load", () => {
print("BBBBBB");
});
};
const playerService = Dependency<PlayerService>(); // Error is from here.

export = () => {
it("player should load", () => {
print("BBBBBB");
});
};
duck
duck3mo ago
jecs? I think ur too obsesssed with ecs ❤️
PepeElToro41
PepeElToro413mo ago
A LOL they have similar names I actually thought jecs was for testing
duck
duck3mo ago
💀 I sometimes type them wrong too

Did you find this page helpful?