I have a "Messages" injectable that represents a service that can fetch a user's messages. This class depends on a "Database" class that logs in to the backend using the credentials of the user.
Now I want to write a test case during which 2 users are logged in at the same time, in order to test automatically whether messages sent from user 1 arrive directly at the inbox of user 2.
Therefore, I need a way to inject two different instances of "Messages" with two different, corresponding instances of "Database".
I tried the following:
beforeEachProviders(() => [
Messages, Database
]);
beforeEach(inject([Messages], (msg) => {
this.msg1 = msg;
}));
beforeEach(inject([Messages], (msg) => {
this.msg2 = msg;
}));
However, it turns out that msg1 and msg2 represent the same instance of "Messages":
it('testcase', () => {
// this.msg1 == this.msg2;
});
Is it possible to tell the injector to create different instances of "Messages" and its dependencies?