add new method Objectmap.getArray()

This commit is contained in:
2016-09-29 22:05:20 +02:00
parent 30e23a77b7
commit 924058c90a
5 changed files with 60 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
import 'typings-test'
import * as events from 'events'
import * as rx from 'rxjs/Rx'
import * as lodash from 'lodash'
import * as should from 'should'
import lik = require('../dist/index')
@ -13,14 +14,14 @@ describe('lik',function(){
let testString4 = 'testString4'
let testString5 = 'testString5'
let testString6 = 'testString6'
it('should create an instance of Stringmap',function(){
it('new lik.Objectmap() -> should create an instance of Stringmap',function(){
testStringmap = new lik.Stringmap()
should(testStringmap).be.instanceof(lik.Stringmap)
})
it('should return false for an string not in Stringmap',function(){
it('lik.Stringmap.checkString -> should return false for an string not in Stringmap',function(){
should(testStringmap.checkString(testString1)).be.false()
})
it('should add an string to Stringmap',function(){
it('lik.Stringmap.addString -> should add an string to Stringmap',function(){
testStringmap.addString(testString1)
testStringmap.addString(testString2)
testStringmap.addString(testString3)
@ -31,26 +32,26 @@ describe('lik',function(){
should(testStringmap.checkMinimatch('*String2')).be.true()
should(testStringmap.checkMinimatch('*String4')).be.false()
})
it('should add an array of strings',function(){
it('lik.Stringmap.addStringArray -> should add an array of strings',function(){
testStringmap.addStringArray([testString4,testString5,testString6])
should(testStringmap.checkMinimatch('*String4')).be.true()
})
it('should remove a string from Stringmap',function(){
it('lik.Stringmap.removeString -> should remove a string from Stringmap',function(){
testStringmap.removeString(testString2)
should(testStringmap.checkString(testString2)).be.false()
})
it('should return a copy of stringArray',function(){
it('lik.Stringmap.getStringArray() -> should return a copy of stringArray',function(){
let clonedArray = testStringmap.getStringArray()
should(clonedArray[0] === 'testString1').be.true()
should(clonedArray[0] === testString1).be.true()
})
it('should register a function to trigger when empty',function(){
it('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty',function(){
testStringmap.registerUntilTrue(
() => { return testStringmap.checkIsEmpty() },
() => { console.log('Stringmap now is empty') }
)
})
it('should remove wipe and then notify',function(){
it('lik.Stringmap.empty() -> should remove wipe and then notify',function(){
testStringmap.wipe()
})
})
@ -68,32 +69,38 @@ describe('lik',function(){
propOne: 'hello',
propTwo: 'hello2'
}
it('should correctly instantiate an Objectmap',function(){
it('new lik.Objectmap() -> should correctly instantiate an Objectmap',function(){
testObjectmap = new lik.Objectmap<ITestObject>()
should(testObjectmap).be.instanceof(lik.Objectmap)
})
it('should correctly add an object to Objectmap',function(){
it('lik.Objectmap.add() -> should correctly add an object to Objectmap',function(){
testObjectmap.add(testObject1)
should(testObjectmap.checkForObject(testObject1)).be.true
should(testObjectmap.checkForObject(testObject2)).be.false
})
it('should correctly remove an object to Objectmap',function(){
it('lik.Objectmap.remove() -> should correctly remove an object to Objectmap',function(){
testObjectmap.add(testObject2)
testObjectmap.remove(testObject1)
should(testObjectmap.checkForObject(testObject1)).be.false
should(testObjectmap.checkForObject(testObject2)).be.true
})
it('should correctly run a function forEach map object',function(){
it('Objectmap.forEach -> should correctly run a function forEach map object',function(){
testObjectmap.forEach(itemArg => {
should(itemArg).have.ownProperty('propOne')
})
})
it('should correctly find an object',function(){
it('lik.Objectmap.find() -> should correctly find an object',function(){
let myObject = {propOne: 'helloThere', propTwo: 'helloAnyway'}
testObjectmap.add(myObject)
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere') })
should(myObject === referenceObject).be.true()
})
it('lik.Objectmap.getArray() -> should return a cloned array', function(){
let myObject = {propOne : 'test1', propTwo: 'wow, how awesome'}
testObjectmap.add(myObject)
let clonedArray = testObjectmap.getArray()
should(lodash.isEqual(clonedArray[clonedArray.length - 1],myObject)).be.true()
})
})
describe('Observablemap',function(){
let testObservablemap: lik.Observablemap