Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
talyssonoc committed Mar 22, 2019
1 parent 47ae676 commit 3e3c19e
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions test/unit/instanceAndUpdate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ describe('instantiating a structure', () => {
type: String,
default: 'Name'
},
password: {
type: String
},
nickname: {
type: String,
default: (instance) => instance.name
},
uuid: {
type: String,
default: (instance) => instance.getUuid()
Expand All @@ -30,27 +37,23 @@ describe('instantiating a structure', () => {
});

it('has access to instance methods', () => {
const user = new User({
name: 'Me'
});
const user = new User();

expect(user.userMethod()).to.equal('I am a user');
});

it('has access to instance attributes created on constructor', () => {
const user = new User({
name: 'Me'
});
const user = new User();

expect(user.userInstanceStuff).to.equal('Stuff value');
});

it('has attributes passed to constructor assigned to the object', () => {
const user = new User({
name: 'Me'
password: 'My password'
});

expect(user.name).to.equal('Me');
expect(user.password).to.equal('My password');
});

it('does not mutate the attributes object passed to the constructor', () => {
Expand All @@ -63,7 +66,6 @@ describe('instantiating a structure', () => {

it('ignores invalid attributes passed to constructor', () => {
const user = new User({
name: 'Myself',
invalid: 'I will be ignored'
});

Expand All @@ -72,11 +74,11 @@ describe('instantiating a structure', () => {

it('reflects instance attributes to #attributes', () => {
const user = new User({
name: 'Self'
password: 'The password'
});

expect(user.name).to.equal('Self');
expect(user.attributes.name).to.equal('Self');
expect(user.password).to.equal('The password');
expect(user.attributes.password).to.equal('The password');
});

describe('attributes initialization', () => {
Expand All @@ -96,6 +98,30 @@ describe('instantiating a structure', () => {
expect(user.uuid).to.equal('10');
});
});

context('when attribute dynamic default uses a static defaultable attribute', () => {
context('when static defaultable attribute uses default value', () => {
it('allows to access the value of that attribute', () => {
const user = new User();

expect(user.nickname).to.equal('Name');
});
});

context('when static defaultable attribute has a value passed to it', () => {
it('allows to access the value of that attribute', () => {
const user = new User({ name: 'This is my name' });

expect(user.nickname).to.equal('This is my name');
});
});
});

it('overrides default value with passed value', () => {
const user = new User({ name: 'Not the default' });

expect(user.name).to.equal('Not the default');
});
});
});
});
Expand Down

0 comments on commit 3e3c19e

Please sign in to comment.