Skip to content

Commit

Permalink
Move all definitions to inside beforeEach blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
talyssonoc committed Jan 24, 2017
1 parent 18c7c40 commit 13600be
Show file tree
Hide file tree
Showing 22 changed files with 792 additions and 492 deletions.
40 changes: 26 additions & 14 deletions test/unit/creatingStructureClass.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ describe('creating an structure class', () => {


describe('using class static methods and properties', () => {
class RawUser {
static staticMethod() {
return 'I am on a static method';
var User;

beforeEach(() => {
class RawUser {
static staticMethod() {
return 'I am on a static method';
}
}
}

RawUser.staticProperty = 'I am a static property';
RawUser.staticProperty = 'I am a static property';

const User = attributes({
name: String
})(RawUser);
User = attributes({
name: String
})(RawUser);
});

it('has access to static methods and properties', () => {
expect(User.staticMethod()).to.equal('I am on a static method');
Expand All @@ -47,9 +51,13 @@ describe('creating an structure class', () => {

describe('using default values for attributes', () => {
context('when the provided default value is a function', () => {
const User = attributes({
age: { type: Number, default: () => 18 }
})(class User {});
var User;

beforeEach(() => {
User = attributes({
age: { type: Number, default: () => 18 }
})(class User {});
});

it('defines the attribute with the default value executing the function', () => {
const user = new User();
Expand All @@ -59,9 +67,13 @@ describe('creating an structure class', () => {
});

context('when the provided default value is a property', () => {
const User = attributes({
age: { type: Number, default: 18 }
})(class User {});
var User;

beforeEach(() => {
User = attributes({
age: { type: Number, default: 18 }
})(class User {});
});

it('defines the attribute with the default value of the property', () => {
const user = new User();
Expand Down
34 changes: 21 additions & 13 deletions test/unit/instanceAndUpdate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ const { expect } = require('chai');
const { attributes } = require('../../src');

describe('instantiating an structure', () => {
const User = attributes({
name: String
})(class User {
constructor() {
this.userInstanceStuff = 'Stuff value';
}

userMethod() {
return 'I am a user';
}
var User;

beforeEach(() => {
User = attributes({
name: String
})(class User {
constructor() {
this.userInstanceStuff = 'Stuff value';
}

userMethod() {
return 'I am a user';
}
});
});

it('has access to instance methods', () => {
Expand Down Expand Up @@ -58,10 +62,14 @@ describe('instantiating an structure', () => {
});

describe('updating an instance', () => {
const User = attributes({
name: String
})(class User {
var User;

beforeEach(() => {
User = attributes({
name: String
})(class User {

});
});

it('updates instance attribute value when assigned a new value', () => {
Expand Down
27 changes: 16 additions & 11 deletions test/unit/serialization/array.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ const { attributes } = require('../../../src');

describe('serialization', () => {
describe('Array', () => {
const Book = attributes({
name: String
})(class Book {});

const User = attributes({
name: String,
books: {
type: Array,
itemType: Book
}
})(class User {});
var Book;
var User;

beforeEach(() => {
Book = attributes({
name: String
})(class Book {});

User = attributes({
name: String,
books: {
type: Array,
itemType: Book
}
})(class User {});
});

context('when all data is present', () => {
it('include all data defined on schema', () => {
Expand Down
21 changes: 13 additions & 8 deletions test/unit/serialization/nestedStructure.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ const { attributes } = require('../../../src');

describe('serialization', () => {
describe('Nested structure', () => {
const Location = attributes({
longitude: Number,
latitude: Number
})(class Location {});
var Location;
var User;

const User = attributes({
name: String,
location: Location
})(class User {});
beforeEach(() => {
Location = attributes({
longitude: Number,
latitude: Number
})(class Location {});

User = attributes({
name: String,
location: Location
})(class User {});
});

context('when all data is present', () => {
it('include all data defined on schema', () => {
Expand Down
12 changes: 8 additions & 4 deletions test/unit/serialization/structure.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ const { attributes } = require('../../../src');

describe('serialization', () => {
describe('Structure', () => {
const User = attributes({
name: String,
age: Number
})(class User {});
var User;

beforeEach(() => {
User = attributes({
name: String,
age: Number
})(class User {});
});

context('when all data is present', () => {
it('include all data defined on schema', () => {
Expand Down
96 changes: 55 additions & 41 deletions test/unit/subclassingStructureClass.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@ const { expect } = require('chai');
const { attributes } = require('../../src');

describe('subclassing an structure with a POJO class', () => {
const User = attributes({
name: String
})(class User {
constructor(attrs, userValue) {
this.userValue = userValue;
this.userStuff = 'User Stuff';
}

userMethod() {
return 'I am a user';
}
});
var User;
var Admin;

class Admin extends User {
constructor(attrs, userValue, otherValue) {
super(attrs, userValue);
this.adminValue = otherValue;
}
beforeEach(() => {
User = attributes({
name: String
})(class User {
constructor(attrs, userValue) {
this.userValue = userValue;
this.userStuff = 'User Stuff';
}

adminMethod() {
return 'I am an admin';
}
}
userMethod() {
return 'I am a user';
}
});

Admin = class Admin extends User {
constructor(attrs, userValue, otherValue) {
super(attrs, userValue);
this.adminValue = otherValue;
}

adminMethod() {
return 'I am an admin';
}
};
});

describe('instantiating an structure subclass', () => {
it('is instance of class and superclass', () => {
Expand Down Expand Up @@ -115,25 +120,29 @@ describe('subclassing an structure with a POJO class', () => {
});

describe('using subclass static methods and properties', () => {
class RawUser {
static staticMethod() {
return 'I am on a static method';
var AdminStructure;

beforeEach(() => {
class RawUser {
static staticMethod() {
return 'I am on a static method';
}
}
}

RawUser.staticProperty = 'I am a static property';
RawUser.staticProperty = 'I am a static property';

const UserStructure = attributes({
name: String
})(RawUser);
const UserStructure = attributes({
name: String
})(RawUser);

class AdminStructure extends UserStructure {
static staticAdminMethod() {
return 'I am also on a static method';
}
}
AdminStructure = class AdminStructure extends UserStructure {
static staticAdminMethod() {
return 'I am also on a static method';
}
};

AdminStructure.staticAdminProperty = 'I am also a static property';
AdminStructure.staticAdminProperty = 'I am also a static property';
});

it('has access to static methods and properties', () => {
expect(AdminStructure.staticMethod()).to.equal('I am on a static method');
Expand All @@ -145,13 +154,18 @@ describe('subclassing an structure with a POJO class', () => {
});

describe('subclassing an structure with another structure', () => {
const User = attributes({
name: String
})(class User {});
var Admin;
var User;

beforeEach(() => {
User = attributes({
name: String
})(class User {});

const Admin = attributes({
level: Number
})(class Admin extends User {});
Admin = attributes({
level: Number
})(class Admin extends User {});
});

it('uses the extended schema', () => {
const admin = new Admin({
Expand Down
16 changes: 10 additions & 6 deletions test/unit/typeCoercion/array.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ const { attributes } = require('../../../src');

describe('type coercion', () => {
describe('Array', () => {
const User = attributes({
books: {
type: Array,
itemType: String
}
})(class User {});
var User;

beforeEach(() => {
User = attributes({
books: {
type: Array,
itemType: String
}
})(class User {});
});

it('does not coerces undefined', () => {
const user = new User({
Expand Down
21 changes: 13 additions & 8 deletions test/unit/typeCoercion/arraySubclass.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ const { attributes } = require('../../../src');

describe('type coercion', () => {
describe('Array subclass', () => {
class Collection extends Array {}

const User = attributes({
books: {
type: Collection,
itemType: String
}
})(class User {});
var Collection;
var User;

beforeEach(() => {
Collection = class Collection extends Array {}

User = attributes({
books: {
type: Collection,
itemType: String
}
})(class User {});
});

it('does not coerces undefined', () => {
const user = new User({
Expand Down
10 changes: 7 additions & 3 deletions test/unit/typeCoercion/boolean.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ const { attributes } = require('../../../src');

describe('type coercion', () => {
describe('Boolean', () => {
const User = attributes({
isAdmin: Boolean
})(class User {});
var User;

beforeEach(() => {
User = attributes({
isAdmin: Boolean
})(class User {});
});

it('does not coerces undefined', () => {
const user = new User({
Expand Down
Loading

0 comments on commit 13600be

Please sign in to comment.