Skip to content

Instantly share code, notes, and snippets.

@phatnguyenuit
Created September 13, 2023 13:50
Show Gist options
  • Save phatnguyenuit/c926df4d9998abd5635a849f300bfb3f to your computer and use it in GitHub Desktop.
Save phatnguyenuit/c926df4d9998abd5635a849f300bfb3f to your computer and use it in GitHub Desktop.
Using global utility for Jest pattern
declare global {
namespace NodeJS {
interface Global {
yourUtility(...args: any[]): void;
}
}
}
module.exports = {
...jestConfigurations,
setupFilesAfterEnv: ['<rootDir>/src/setupTest.ts']
};
import yourUtility from 'utils/yourUtility';
beforeAll(() => {
global.yourUtility = yourUtility;
});
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