Skip to content

Commit 3f296d4

Browse files
committed
spec: add test for media access
1 parent 53b690a commit 3f296d4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ function getAuthStatus(type) {
1818
}
1919

2020
function askForMediaAccess(type, callback) {
21-
if (['microphone', 'camera'].includes(type)) {
21+
if (!['microphone', 'camera'].includes(type)) {
2222
throw new TypeError(`${type} must be either 'camera' or 'microphone'`)
2323
}
24+
2425
if (typeof callback !== 'function') {
2526
throw new TypeError(`callback must be a function`)
2627
}

test/module.spec.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { expect } = require('chai')
22
const {
3-
getAuthStatus
3+
getAuthStatus,
4+
askForMediaAccess
45
} = require('../index')
56

67
describe('node-mac-permissions', () => {
@@ -28,4 +29,14 @@ describe('node-mac-permissions', () => {
2829
}
2930
})
3031
})
31-
})
32+
33+
describe('askForMediaAccess(type, callback)', () => {
34+
it ('throws on invalid media types', () => {
35+
expect(() => {
36+
askForMediaAccess('bad-type', (status) =>{
37+
console.log(status)
38+
})
39+
}).to.throw(/bad-type must be either 'camera' or 'microphone'/)
40+
})
41+
})
42+
})

0 commit comments

Comments
 (0)