Skip to content

Commit 9bd9123

Browse files
committed
lesson4
1 parent 70a15e0 commit 9bd9123

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lesson4.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// import { Permissions } from '@/lib/permissions'
2+
let args = []
3+
4+
// Replace the imported Persmissions with a custom mock implementation
5+
const Permissions = {
6+
granted(...params) {
7+
args.push([...params])
8+
}
9+
}
10+
11+
// Potential User class
12+
class User {}
13+
14+
const user = new User()
15+
16+
// Function that uses the Permissions dependency
17+
// and now uses the mocked implementation
18+
function isUserAdmin() {
19+
return Permissions.granted(user, 'admin')
20+
}
21+
22+
const test = function () {
23+
isUserAdmin()
24+
return JSON.stringify(args[0]) === JSON.stringify([user, 'admin'])
25+
}
26+
27+
// Execute the test and print out the result
28+
console.log(test())

0 commit comments

Comments
 (0)