Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): 84% coverage for utilities/EnvInfo.ts #1620

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"io-ts-promise": "^2.0.2",
"jest-config": "^27.3.1",
"jest-fetch-mock": "^3.0.3",
"jest-webgl-canvas-mock": "^0.2.3",
"less": "^4.1.1",
"less-loader": "^7.1.1",
"lodash": "^4.17.21",
Expand Down
31 changes: 31 additions & 0 deletions utilities/EnvInfo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { EnvInfo } from './EnvInfo'
import 'jest-canvas-mock'
import 'jest-webgl-canvas-mock'
global.console.warn = jest.fn()
HTMLCanvasElement.prototype.getContext = jest.fn()
// HTMLCanvasElement. = jest.fn()
// HTMLCanvasElement.prototype.getParameter = jest.fn()

let canvas

describe('init', () => {
beforeEach(() => {
canvas = document.createElement('canvas')
})
test('constructor success', () => {
const envinfo = new EnvInfo()
// const gl =
// canvas.getContext('webgl') || canvas.getContext('experimental-webgl')
expect(jest.spyOn(canvas, 'getContext')).toHaveBeenCalled()
// expect(jest.spyOn(gl, 'getExtension')).toHaveBeenCalled()

// gl is currently commented out because of the Error: `Cannot spyOn on a primitive value; undefined given`
})
test('constructor fail', () => {
HTMLCanvasElement.prototype.getContext = () => {
throw new Error('mocked error')
}
const envinfo = new EnvInfo()
expect(console.warn).toHaveBeenCalled()
})
})