-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(instrumentation-react-native-navigation) adding unit tests
- Loading branch information
1 parent
ab87452
commit d75cb7f
Showing
9 changed files
with
173 additions
and
25 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
plugins/node/instrumentation-react-native-navigation/.mocharc.yml
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
extension: ["ts", "tsx"] | ||
spec: ["test/**/*.test.tsx"] | ||
spec: ["test/**/*.test.tsx", "test/**/*.test.ts"] | ||
require: ["jsdom.register.js", "babel.register.js"] |
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
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
File renamed without changes.
73 changes: 73 additions & 0 deletions
73
plugins/node/instrumentation-react-native-navigation/test/useConsole.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { renderHook } from '@testing-library/react'; | ||
import useConsole from '../src/utils/hooks/useConsole'; | ||
import { beforeEach, afterEach } from 'mocha'; | ||
import sinon from 'sinon'; | ||
|
||
describe('useConsole.ts', function () { | ||
const sandbox = sinon.createSandbox(); | ||
|
||
let mockConsoleInfo: sinon.SinonSpy; | ||
let mockConsoleWarn: sinon.SinonSpy; | ||
|
||
beforeEach(function () { | ||
mockConsoleInfo = sandbox.spy(console, 'info'); | ||
mockConsoleWarn = sandbox.spy(console, 'warn'); | ||
}); | ||
|
||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('should not to print messages', () => { | ||
const { result } = renderHook(() => useConsole(false)); | ||
const customConsole = result.current; | ||
|
||
customConsole.info('Info log.'); | ||
customConsole.warn('Warn log.'); | ||
|
||
sandbox.assert.notCalled(mockConsoleInfo); | ||
sandbox.assert.notCalled(mockConsoleWarn); | ||
}); | ||
|
||
it('should print messages', () => { | ||
const { result } = renderHook(() => useConsole(true)); | ||
const customConsole = result.current; | ||
|
||
customConsole.info('Info log.'); | ||
customConsole.warn('Warn log.'); | ||
|
||
sandbox.assert.calledOnceWithExactly(mockConsoleInfo, 'Info log.'); | ||
sandbox.assert.calledOnceWithExactly(mockConsoleWarn, 'Warn log.'); | ||
}); | ||
|
||
it('should work as expected when the argument is updated', () => { | ||
const { result: customConsoleNotPrinting } = renderHook(() => | ||
useConsole(false) | ||
); | ||
|
||
customConsoleNotPrinting.current.info('Info log.'); | ||
sandbox.assert.notCalled(mockConsoleInfo); | ||
|
||
const { result: customConsolePrinting } = renderHook(() => | ||
useConsole(true) | ||
); | ||
|
||
customConsolePrinting.current.info('Info log printed.'); | ||
sandbox.assert.calledOnceWithExactly(mockConsoleInfo, 'Info log printed.'); | ||
}); | ||
}); |