Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: this.AuthService is not a constructor #50

Open
gfkauer opened this issue Jan 9, 2022 · 0 comments
Open

TypeError: this.AuthService is not a constructor #50

gfkauer opened this issue Jan 9, 2022 · 0 comments

Comments

@gfkauer
Copy link

gfkauer commented Jan 9, 2022

Dada a classe:

class UsersController {
    constructor(User, AuthService) {
        this.User = User;
        this.AuthService = AuthService;
    }

    async authenticate(req, res) {
        const authService = new this.AuthService(this.User);
        const user = await authService.authenticate(req.body);
        if (!user) {
            return res.sendStatus(401);
        }
        const token = this.AuthService.generateToken({
            name: user.name,
            email: user.email,
            password: user.password,
            role: user.role
        });
        return res.send({ token });
    }
}

export default UsersController;

os testes unitários apresentam o erro:

Controller: Users
       login
         should return 401 when the user can not be found:
     TypeError: this.AuthService is not a constructor
      at UsersController.authenticate (src/controllers/users.js:69:29)
      at Context.<anonymous> (test/unit/controllers/users_spec.js:298:35)
      at processImmediate (node:internal/timers:464:21)

para ver o codigo completo atual pode verificar em:
https://github.com/gfkauer/to-do-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant