Created
September 13, 2023 13:50
-
-
Save phatnguyenuit/c926df4d9998abd5635a849f300bfb3f to your computer and use it in GitHub Desktop.
Using global utility for Jest pattern
This file contains 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 characters
declare global { | |
namespace NodeJS { | |
interface Global { | |
yourUtility(...args: any[]): void; | |
} | |
} | |
} |
This file contains 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 characters
module.exports = { | |
...jestConfigurations, | |
setupFilesAfterEnv: ['<rootDir>/src/setupTest.ts'] | |
}; |
This file contains 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 characters
import yourUtility from 'utils/yourUtility'; | |
beforeAll(() => { | |
global.yourUtility = yourUtility; | |
}); |
This file contains 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 characters
test('your test case here', () => { | |
yourUtility(some_args); | |
// your actions | |
// your assertions | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment