-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow mocking property value in tests (#13496)
- Loading branch information
1 parent
a325f87
commit e77128b
Showing
15 changed files
with
689 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {isLocalhost} from '../utils'; | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('isLocalhost should detect localhost environment', () => { | ||
jest.replaceProperty(process, 'env', {HOSTNAME: 'localhost'}); | ||
|
||
expect(isLocalhost()).toBe(true); | ||
}); | ||
|
||
it('isLocalhost should detect non-localhost environment', () => { | ||
jest.replaceProperty(process, 'env', {HOSTNAME: 'example.com'}); | ||
|
||
expect(isLocalhost()).toBe(false); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isLocalhost() { | ||
return process.env.HOSTNAME === 'localhost'; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
|
||
import {afterEach, beforeEach, expect, it, jest} from '@jest/globals'; | ||
import {isLocalhost} from '../utils'; | ||
|
||
let replacedEnv: jest.Replaced<typeof process.env> | undefined = undefined; | ||
|
||
beforeEach(() => { | ||
replacedEnv = jest.replaceProperty(process, 'env', {}); | ||
}); | ||
|
||
afterEach(() => { | ||
replacedEnv?.restore(); | ||
}); | ||
|
||
it('isLocalhost should detect localhost environment', () => { | ||
replacedEnv.replaceValue({HOSTNAME: 'localhost'}); | ||
|
||
expect(isLocalhost()).toBe(true); | ||
}); | ||
|
||
it('isLocalhost should detect non-localhost environment', () => { | ||
expect(isLocalhost()).toBe(false); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
|
||
export function isLocalhost() { | ||
return process.env.HOSTNAME === 'localhost'; | ||
} |
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
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
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
Oops, something went wrong.