11import Eco from "../../src/eco" ;
22
3- function mockEntityPrototype ( ) {
4- return jasmine . createSpyObj ( "Entity" , [ "defineComponent" ] ) ;
5- }
6-
73function mockEntityCollection ( ) {
84 return jasmine . createSpyObj ( "entityCollection" , [
95 "add" ,
@@ -14,18 +10,20 @@ function mockEntityCollection() {
1410
1511describe ( "Eco" , ( ) => {
1612 it ( "should return entity instances" , ( ) => {
17- const Entity = function ( ) { } ;
13+ const entity = "foo" ;
14+ const createEntity = jasmine . createSpy ( ) . and . returnValue ( entity ) ;
15+
1816 const entityCollection = mockEntityCollection ( ) ;
19- const eco = new Eco ( Entity , entityCollection ) ;
17+ const eco = new Eco ( createEntity , entityCollection ) ;
2018
2119 const instance = eco . entity ( ) ;
22- expect ( instance instanceof Entity ) . toBeTruthy ( ) ;
20+ expect ( createEntity ) . toHaveBeenCalledWith ( eco ) ;
21+ expect ( instance ) . toBe ( entity ) ;
2322 expect ( entityCollection . add ) . toHaveBeenCalledWith ( instance ) ;
2423 } ) ;
2524
2625 it ( "should call the onChange function property if a component changes" , done => {
27- const Entity = function ( ) { } ;
28- const eco = new Eco ( Entity , mockEntityCollection ( ) ) ;
26+ const eco = new Eco ( ( ) => ( { } ) , mockEntityCollection ( ) ) ;
2927
3028 const entity = { } ;
3129 const component = "foo" ;
@@ -44,46 +42,41 @@ describe("Eco", () => {
4442 } ) ;
4543
4644 it ( "should increment the entityCollection version when a component is added" , ( ) => {
47- const Entity = function ( ) { } ;
4845 const entityCollection = mockEntityCollection ( ) ;
49- const eco = new Eco ( Entity , entityCollection ) ;
46+ const eco = new Eco ( ( ) => ( { } ) , entityCollection ) ;
5047
5148 const entity = { } ;
5249 eco . onComponentChanged ( entity , "foo" , "bar" , undefined ) ;
5350 expect ( entityCollection . incVersion ) . toHaveBeenCalledWith ( entity , "foo" ) ;
5451 } ) ;
5552
5653 it ( "should increment the entityCollection version when a component is removed" , ( ) => {
57- const Entity = function ( ) { } ;
5854 const entityCollection = mockEntityCollection ( ) ;
59- const eco = new Eco ( Entity , entityCollection ) ;
55+ const eco = new Eco ( ( ) => ( { } ) , entityCollection ) ;
6056
6157 const entity = { } ;
6258 eco . onComponentChanged ( entity , "foo" , undefined , "bar" ) ;
6359 expect ( entityCollection . incVersion ) . toHaveBeenCalledWith ( entity , "foo" ) ;
6460 } ) ;
6561
6662 it ( "should not increment the entityCollection version if a component value has changed" , ( ) => {
67- const Entity = function ( ) { } ;
6863 const entityCollection = mockEntityCollection ( ) ;
69- const eco = new Eco ( Entity , entityCollection ) ;
64+ const eco = new Eco ( ( ) => ( { } ) , entityCollection ) ;
7065
7166 eco . onComponentChanged ( { } , "foo" , "foo" , "bar" ) ;
7267 expect ( entityCollection . incVersion ) . not . toHaveBeenCalled ( ) ;
7368 } ) ;
7469
7570 it ( "should return an array of all its entities" , ( ) => {
76- const Entity = function ( ) { } ;
7771 const entityCollection = mockEntityCollection ( ) ;
78- const eco = new Eco ( Entity , entityCollection ) ;
72+ const eco = new Eco ( ( ) => ( { } ) , entityCollection ) ;
7973 expect ( eco . all ) . toBe ( entityCollection . entities ) ;
8074 } ) ;
8175
8276 it ( "should create and return iterator instances" , ( ) => {
83- const Entity = function ( ) { } ;
8477 const entityCollection = mockEntityCollection ( ) ;
8578 const createIterator = jasmine . createSpy ( "createIterator" ) ;
86- const eco = new Eco ( Entity , entityCollection , createIterator ) ;
79+ const eco = new Eco ( ( ) => ( { } ) , entityCollection , createIterator ) ;
8780
8881 const filter = { } ;
8982 createIterator . and . returnValue ( filter ) ;
@@ -98,10 +91,9 @@ describe("Eco", () => {
9891 } ) ;
9992
10093 it ( "should create and return filter instances with custom filter functions" , ( ) => {
101- const Entity = function ( ) { } ;
10294 const entityCollection = mockEntityCollection ( ) ;
10395 const createIterator = jasmine . createSpy ( "createIterator" ) ;
104- const eco = new Eco ( Entity , entityCollection , createIterator ) ;
96+ const eco = new Eco ( ( ) => ( { } ) , entityCollection , createIterator ) ;
10597
10698 const filter = { } ;
10799 createIterator . and . returnValue ( filter ) ;
@@ -118,19 +110,17 @@ describe("Eco", () => {
118110 } ) ;
119111
120112 it ( "should remove entities that have been disabled" , ( ) => {
121- const Entity = function ( ) { } ;
122113 const entityCollection = mockEntityCollection ( ) ;
123- const eco = new Eco ( Entity , entityCollection ) ;
114+ const eco = new Eco ( ( ) => ( { } ) , entityCollection ) ;
124115 const entity = eco . entity ( ) ;
125116
126117 eco . onEntityStatusChanged ( entity , false ) ;
127118 expect ( entityCollection . remove ) . toHaveBeenCalledWith ( entity ) ;
128119 } ) ;
129120
130121 it ( "should re-add entities that have been re-enabled" , ( ) => {
131- const Entity = function ( ) { } ;
132122 const entityCollection = mockEntityCollection ( ) ;
133- const eco = new Eco ( Entity , entityCollection ) ;
123+ const eco = new Eco ( ( ) => ( { } ) , entityCollection ) ;
134124 const entity = eco . entity ( ) ;
135125
136126 eco . onEntityStatusChanged ( entity , false ) ;
0 commit comments