Skip to content

Commit

Permalink
test: use describeNode and describeBrowser accordingly
Browse files Browse the repository at this point in the history
Signed-off-by: Cuichen Li <[email protected]>
  • Loading branch information
cuichenli committed Mar 4, 2022
1 parent 508fce0 commit abb3d3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit abb3d3a

Please sign in to comment.