Skip to content

Commit

Permalink
web: mock _.uniqueId() in tests (sourcegraph#21391)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerybugakov authored May 26, 2021
1 parent 36401eb commit 2540d10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`codeHost handleCodeHost() Decorations decorates a diff code view 1`] = `
<div
class="test test-6 sg-mounted"
class="test test-test-id sg-mounted"
id="code"
>
<div
Expand Down Expand Up @@ -91,7 +91,7 @@ exports[`codeHost handleCodeHost() Decorations decorates a diff code view 1`] =

exports[`codeHost handleCodeHost() Decorations decorates a diff code view 2`] = `
<div
class="test test-6 sg-mounted"
class="test test-test-id sg-mounted"
id="code"
>
<div
Expand Down Expand Up @@ -173,7 +173,7 @@ exports[`codeHost handleCodeHost() Decorations decorates a diff code view 2`] =

exports[`codeHost handleCodeHost() Decorations decorates a diff code view 3`] = `
<div
class="test test-6 sg-mounted"
class="test test-test-id sg-mounted"
id="code"
>
<div
Expand Down
7 changes: 7 additions & 0 deletions client/shared/dev/mockUniqueId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// The value returned by the `_.uniqueId()` function depends on the number of previous calls
// because it maintains an internal variable that increments on each call.
// Mock `_.uniqueId()` to avoid updating snapshots once the sequence or number of tests using this helper changes.

// The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables
// eslint-disable-next-line unicorn/consistent-function-scoping
jest.mock('lodash/uniqueId', () => (prefix = '') => `${prefix}test-id`)
16 changes: 8 additions & 8 deletions client/web/src/nav/__snapshots__/NavLinks.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ exports[`NavLinks authed Sourcegraph.com /foo 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-7"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down Expand Up @@ -1328,7 +1328,7 @@ exports[`NavLinks authed Sourcegraph.com /search 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-8"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down Expand Up @@ -2128,7 +2128,7 @@ exports[`NavLinks authed self-hosted /foo 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-5"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down Expand Up @@ -2899,7 +2899,7 @@ exports[`NavLinks authed self-hosted /search 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-6"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down Expand Up @@ -3439,7 +3439,7 @@ exports[`NavLinks unauthed Sourcegraph.com /foo 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-3"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down Expand Up @@ -3776,7 +3776,7 @@ exports[`NavLinks unauthed Sourcegraph.com /search 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-4"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down Expand Up @@ -4080,7 +4080,7 @@ exports[`NavLinks unauthed self-hosted /foo 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-1"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down Expand Up @@ -4374,7 +4374,7 @@ exports[`NavLinks unauthed self-hosted /search 1`] = `
>
<span
class="test-command-list-button command-list__popover-button btn btn-link"
id="command-list-popover-button-2"
id="command-list-popover-button-test-id"
role="button"
>
<svg
Expand Down
1 change: 1 addition & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const config = {
require.resolve('abort-controller/polyfill'),
path.join(__dirname, 'client/shared/dev/fetch'),
path.join(__dirname, 'client/shared/dev/setLinkComponentForTest.ts'),
path.join(__dirname, 'client/shared/dev/mockUniqueId.ts'),
// Enzyme setup file
path.join(__dirname, 'client/shared/dev/enzymeSetup.js'),
],
Expand Down

0 comments on commit 2540d10

Please sign in to comment.