-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.spec.js
43 lines (40 loc) · 1.05 KB
/
functions.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { autobindMethods, callOrAssign, noop } from './functions.js'
import { expect } from 'chai'
describe('Functions', function () {
it('noop', () => {
expect(() => noop()).to.not.throw
expect(noop.call({ hello: 'hello' })).to.be.deep.equal({ hello: 'hello' })
})
it('autobindMethods', () => {
const methods = autobindMethods(
{
name: 'me',
onMount() {
return this
},
onUnmount() {
return this
},
},
['onMount', 'onUnmount'],
)
expect(methods.onMount().name).to.be.equal('me')
expect(methods.onUnmount().name).to.be.equal('me')
})
it('callOrAssign', () => {
/* eslint-disable fp/no-class */
class MyClas {
hello() {
return 'me'
}
}
/* eslint-enable fp/no-class */
expect(callOrAssign(() => ({ hello: 'hello' }))).to.be.deep.equal({
hello: 'hello',
})
expect(callOrAssign({ hello: 'hello' })).to.be.deep.equal({
hello: 'hello',
})
expect(callOrAssign(MyClas).hello()).to.be.equal('me')
})
})