Skip to content

How to stop service onInit hook from running when testing #2147

Answered by Romakita
janek515 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @janek515

The $onInit is always emitted and changing that is not recommended.

The simple solution if to set an option to by-pass connection during the bootstrap sequence:

beforeAll(PlatformTest.bootstrap(Server, {
   mydb: {
      disabled: true
   }
}));

@Injectable()
class MyConnectionService {
    @Constant("mydb.disabled", false)
    disabled: boolean;

   $onInit() {
     if (!this.disabled) {
        ///....
     }
   }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by janek515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants