I have spec like this:
describe('test', function() {
function CreateApple(type,color, width){
this.type= type
this.color=color;
this.width=width;
}
CreateApple.prototype.eat= function(){
return console.log("eat mniam, mniam");
}
CreateApple.prototype.height = 55;
CreateApple.prototype.xxx={
module1: 1,
hhh: 2,
tablice:{
tab1: function(num){return num},
tab2: 44,
}
}
it('test1', function() {
var apple1 = new CreateApple("goodone", "red", 34);
apple1.eat();
console.log(apple1.type);
console.log(apple1.height);
var ttt= apple1.xxx.hhh;
var uuu= apple1.xxx.tablice.tab1(4);
console.log(ttt+" "+uuu);
});
});
When I run it using my conf.js everything works excellent. Now I would like to use Page Object and leave in my spec.js only 'test1' which means that constructor 'CreateApple' and its prototypes shoud go to the other file. Can anyone tell me how my new 'page object' file should look like?? I got something like below but I doesnt work:
spec.js
require('../jgh/page4.js');
describe('test', function() {
it('test1', function() {
var apple1 = new CreateApple("goodone", "red", 34);
apple1.eat();
console.log(apple1.type);
console.log(apple1.height);
var ttt= apple1.xxx.hhh;
var uuu= apple1.xxx.tablice.tab1(4);
console.log(ttt+" "+uuu);
});
});
and my page4.js
modules.exports =function CreateApple(type,color, width){
this.type= type
this.color=color;
this.width=width;
}
CreateApple.prototype.eat= function(){
return console.log("eat mniam, mniam");
}
CreateApple.prototype.height = 55;
CreateApple.prototype.xxx={
module1: 1,
hhh: 2,
tablice:{
tab1: function(num){return num},
tab2: 44,
}
}
I get:
Error: ReferenceError: CreateApple is not defined