diff --git a/packages/opentelemetry-resources/test/detectors/browser/BrowserDetector.test.ts b/packages/opentelemetry-resources/test/detectors/browser/BrowserDetector.test.ts index 614905cd4b3..7543d294386 100644 --- a/packages/opentelemetry-resources/test/detectors/browser/BrowserDetector.test.ts +++ b/packages/opentelemetry-resources/test/detectors/browser/BrowserDetector.test.ts @@ -16,33 +16,22 @@ import * as sinon from 'sinon'; import { Resource } from '../../../src'; import { browserDetector } from '../../../src/detectors/BrowserDetector'; +import { describeBrowser } from '../../util'; import { assertResource, assertEmptyResource, } from '../../util/resource-assertions'; -describe('browserDetector()', () => { - beforeEach(() => { - (globalThis.window as {}) = {}; - sinon.stub(globalThis, 'window').value({ - document: 'document', - navigator: { - userAgent: '', - } - }); - }); +describeBrowser('browserDetector()', () => { afterEach(() => { sinon.restore(); }); it('should return browser information', async () => { - sinon.stub(globalThis, 'window').value({ - navigator: { - userAgent: 'dddd', - }, - document: 'document' + sinon.stub(window, 'navigator').value({ + userAgent: 'dddd', }); const resource: Resource = await browserDetector.detect(); @@ -53,6 +42,9 @@ describe('browserDetector()', () => { }); }); it('should return empty resources if version is missing', async () => { + sinon.stub(window, 'navigator').value({ + userAgent: '', + }); const resource: Resource = await browserDetector.detect(); assertEmptyResource(resource); }); diff --git a/packages/opentelemetry-resources/test/detectors/node/BrowserDetector.test.ts b/packages/opentelemetry-resources/test/detectors/node/BrowserDetector.test.ts index d5b51e44359..27d7bdfeffb 100644 --- a/packages/opentelemetry-resources/test/detectors/node/BrowserDetector.test.ts +++ b/packages/opentelemetry-resources/test/detectors/node/BrowserDetector.test.ts @@ -13,28 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as sinon from 'sinon'; import { Resource } from '../../../src'; import { browserDetector } from '../../../src/detectors/BrowserDetector'; +import { describeNode } from '../../util'; import { assertEmptyResource, } from '../../util/resource-assertions'; -describe('browserDetector()', () => { - beforeEach(() => { - (globalThis.window as {}) = {}; - sinon.stub(globalThis, 'window').value({ - navigator: { - userAgent: '', - } - }); - }); - - afterEach(() => { - sinon.restore(); - }); - +describeNode('browserDetector()', () => { it('should return empty resources if window.document is missing', async () => { const resource: Resource = await browserDetector.detect(); assertEmptyResource(resource);