diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-15 00:10:45 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-15 00:10:45 +0000 |
| commit | 8b75948934667904196aba319aedda25b00f06ff (patch) | |
| tree | 5f743f14301b5abe868a35fad87bfa0fc0581f04 /spec/frontend/__helpers__/jest_helpers.js | |
| parent | 8f534e1e960eef1f4cfcb7c6d723840523515ffb (diff) | |
| download | gitlab-ce-8b75948934667904196aba319aedda25b00f06ff.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/__helpers__/jest_helpers.js')
| -rw-r--r-- | spec/frontend/__helpers__/jest_helpers.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/frontend/__helpers__/jest_helpers.js b/spec/frontend/__helpers__/jest_helpers.js new file mode 100644 index 00000000000..273d2c91966 --- /dev/null +++ b/spec/frontend/__helpers__/jest_helpers.js @@ -0,0 +1,22 @@ +/* +@module + +This method provides convenience functions to help migrating from Karma/Jasmine to Jest. + +Try not to use these in new tests - this module is provided primarily for convenience of migrating tests. + */ + +/** + * Creates a plain JS object pre-populated with Jest spy functions. Useful for making simple mocks classes. + * + * @see https://jasmine.github.io/2.0/introduction.html#section-Spies:_%3Ccode%3EcreateSpyObj%3C/code%3E + * @param {string} baseName Human-readable name of the object. This is used for reporting purposes. + * @param methods {string[]} List of method names that will be added to the spy object. + */ +export function createSpyObj(baseName, methods) { + const obj = {}; + methods.forEach((method) => { + obj[method] = jest.fn().mockName(`${baseName}#${method}`); + }); + return obj; +} |
