Created
August 30, 2019 05:15
-
-
Save techieshark/151aeef6f4fc336738de0a661565d0b9 to your computer and use it in GitHub Desktop.
Revisions
-
techieshark created this gist
Aug 30, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ // __mocks__/stripe.ts: Jest Mock for Stripe class /** * Fake a response from stripe.customers.list(). * @example * mockStripeCustomerList(1) === { data: ['fake customer'], object: 'list', … } * @param count number of fake customers to return */ export const mockStripeCustomerList = (count: number) => ({ data: (new Array(count)).fill('fake customer'), object: 'list', url: 'fake/v1/customers/', }); const stripeCustomersList = () => mockStripeCustomerList(0); const mock = jest.fn().mockImplementation(() => { return { customers: { list: () => jest.fn().mockImplementation(stripeCustomersList), }, }; }); export default mock; // Some other useful reads: // https://stackoverflow.com/questions/51495473/typescript-and-jest-avoiding-type-errors-on-mocked-functions // https://github.com/stripe/stripe-mock // https://jestjs.io/docs/en/es6-class-mocks // https://stackoverflow.com/a/57499771/1024811 (stripe jest mock) // https://github.com/maurocarrero/sinon-jest-cheatsheet#return-value