Mocking Passport.js (local strategy) in a unit test

前端 未结 3 1780
你的背包
你的背包 2021-02-05 16:28

I am using the local strategy of Passport.js to authenticate users for my API. I am writing tests for this API, and I need a way of mocking Passport.js in the tests to simulate

相关标签:
3条回答
  • 2021-02-05 16:53

    One possible option: in your test setup, you can passport.use a mock strategy under the local name:

    passport.use('local', new MockStrategy());

    Implement MockStrategy to pass the request, or whatever your test needs.

    0 讨论(0)
  • 2021-02-05 17:07

    A bit late, but I did mock passport.js in a project and created a gist with a basic howto. Should work fine (I used passport version ~0.1.16).

    0 讨论(0)
  • 2021-02-05 17:10

    you can use the http request objects in node and automate rest requests against your API the same way as it would occur in the real world. Look at node supertest module.

    0 讨论(0)
提交回复
热议问题