uci-utils-bind-functions/test/bind-funcs.test.js

27 lines
957 B
JavaScript

let date = new Date(Date.now())
console.log('run:', date.getMinutes(), ':', date.getSeconds())
import { expect } from 'chai'
import { bindFuncs } from '../src/bind-functions'
describe('Bind Functions Utility - ', function () {
it('Should bind context to function in array', function () {
let context = {prop:'test string'}
let array = [1,'2',{test:true},function test() {return this.prop}]
let boundArray = bindFuncs(array,context)
expect(boundArray[3]()).to.equal('test string')
expect(boundArray[1]).to.equal('2')
})
it('Should bind context to function deep in object', function () {
let context = {prop:'obj test string'}
let obj = {prop:true,prop2:'test',prop3:{test:'string unchanged',prop4:function test() {return this.prop}}}
let boundObject = bindFuncs(obj,context)
expect(boundObject.prop3.prop4()).to.equal('obj test string')
expect(boundObject.prop3.test).to.equal('string unchanged')
})
})