lik/test/test.ts

84 lines
3.5 KiB
TypeScript
Raw Normal View History

2016-07-21 22:16:45 +00:00
import "typings-test";
import lik = require("../dist/index");
import "should";
describe("lik",function(){
describe("Stringmap",function(){
let testStringmap:lik.Stringmap;
let testString1 = "testString1";
let testString2 = "testString2";
let testString3 = "testString3";
it("should create an instance of Stringmap",function(){
testStringmap = new lik.Stringmap();
testStringmap.should.be.instanceof(lik.Stringmap);
});
it("should return false for an string not in Stringmap",function(){
testStringmap.checkString(testString1).should.be.false();
});
it("should add an string to Stringmap",function(){
testStringmap.addString(testString1);
testStringmap.addString(testString2);
testStringmap.addString(testString3);
testStringmap.checkString(testString1).should.be.true();
testStringmap.checkString(testString2).should.be.true();
testStringmap.checkString(testString3).should.be.true();
2016-07-24 16:51:56 +00:00
testStringmap.checkMinimatch("*String1").should.be.true();
testStringmap.checkMinimatch("*String2").should.be.true();
testStringmap.checkMinimatch("*String4").should.be.false();
2016-07-21 22:16:45 +00:00
});
it("should remove a string from Stringmap",function(){
testStringmap.removeString(testString2);
testStringmap.checkString(testString2).should.be.false();
});
it("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(){
testStringmap.wipe();
})
2016-07-30 22:54:46 +00:00
});
describe("Objectmap",function(){
interface ITestObject {
propOne:string;
propTwo:string;
}
let testObjectmap:lik.Objectmap;
let testObject1:ITestObject = {
propOne: "hello",
propTwo: "hello2"
};
let testObject2:ITestObject = {
propOne: "hello",
propTwo: "hello2"
};
it("should correctly instantiate an Objectmap",function(){
testObjectmap = new lik.Objectmap();
testObjectmap.should.be.instanceof(lik.Objectmap);
});
it("should correctly add an object to Objectmap",function(){
testObjectmap.add(testObject1);
testObjectmap.checkForObject(testObject1).should.be.true;
testObjectmap.checkForObject(testObject2).should.be.false;
});
it("should correctly remove an object to Objectmap",function(){
testObjectmap.add(testObject2);
testObjectmap.remove(testObject1);
testObjectmap.checkForObject(testObject1).should.be.false;
testObjectmap.checkForObject(testObject2).should.be.true;
});
2016-07-31 12:36:28 +00:00
it("should correctly run a function forEach map object",function(){
testObjectmap.forEach(itemArg => {
itemArg.should.have.ownProperty("propOne");
})
});
it("should correctly find an object",function(){
let myObject = {item1: "hello",item2: "hello2"};
testObjectmap.add(myObject);
let referenceObject = testObjectmap.find((itemArg) => {return (itemArg.item1 == "hello")});
(myObject == referenceObject).should.be.true();
});
2016-07-21 22:16:45 +00:00
})
});