Hi, Is there a way to run unit tests without calli...
# support-questions-legacy
u
Hi, Is there a way to run unit tests without calling super token.init() function? Currently, I have to run docker container to start supertokens core before I can run the unit tests. I’m trying to test following code
Copy code
@Mutation(() => AdminUser)
  @UseGuards(new AuthGuard())
  async addAdminUser(
    @Args('registrationInput') registrationInput: RegistrationInput,
  ) {
    const { email, password, role } = registrationInput;
    const response = await EmailPassword.signUp('public', email, password);
    if (response.status === 'EMAIL_ALREADY_EXISTS_ERROR') {
      LoggerService.logger.error('Email already exists');
      throw new BadRequestException('Email already exists');
    }
    if (response.status === 'OK') {
    // do more additional work, for example:
    // userService.setUserStatus(response.user.id, role);
    }
  }
Following is my testing code. When I run the test I get following error “Initialisation not done. Did you forget to call the SuperTokens.init function?” . To resolve this I have to call following code, where http://localhost:3567 is the supertokens core URI. Which means I need to have running docker container for this unit test, which I want to avoid?
Copy code
beforeEach(async () => {
    supertokens.init({
      supertokens: {
        connectionURI: 'http://localhost:3567',
      },
      appInfo: {
        apiDomain: 'api.supertokens.io',
        appName: 'SuperTokens',
        websiteDomain: 'supertokens.io',
      },
      recipeList: [EmailPassword.init()],
    });
});
 it(‘when user with email is already exists’ , async () => {
    jest.mock('supertokens-node/recipe/emailpassword', () => {
      return {
        EmailPassword: {
          signUp: jest
            .fn()
            .mockReturnValueOnce({ status: 'EMAIL_ALREADY_EXISTS_ERROR' }),
        },
      };
    });
    await registrationResolver.addAdminUser({
      email: ’sample@email.com’,
      role: AdminRole.ADMIN,
    } as RegistrationInput);
 });
14 Views