Jest test for helper file and external function

Viewed 1625

I need to add jest test into the current project. however, I found that helper files here I don't know how to write the test for it

the file stores some functions like this

import SDK from 'privateSDK'

export function login(){
  SDK.login() // Call the native app login if webview
}

If you run the functions on the browser on PC, you will not get any data or effects How Can I test the file?

1 Answers

You need to mock privateSDK module and login method, then you can run your unit tests in an isolated environment which means your unit tests will not depend on the real native app login method.

You can check the docs here: https://jestjs.io/docs/en/mock-functions#mocking-modules

Related