Skip to content

Commit

Permalink
feat(jest): 84% coverage for utilities/EnvInfo.ts (#1620)
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram authored Feb 23, 2022
1 parent d888b1b commit 8518af6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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()
})
})

0 comments on commit 8518af6

Please sign in to comment.