-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MarcL/day2
Day 2 : Initial setup + basic tests
- Loading branch information
Showing
4 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function day2(data) { | ||
if (typeof data === 'object') { | ||
return Object.assign({}, data); | ||
} | ||
|
||
if ((typeof data === 'string') && (data === 'error')) { | ||
throw new Error('Cannot pass error'); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
export default day2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {expect} from 'chai'; | ||
import day2 from '../src/day2'; | ||
|
||
describe('day2 tests', () => { | ||
describe('check data type', () => { | ||
it('should return undefined when no parameters are passed', () => { | ||
expect(day2()).to.be.undefined; | ||
}); | ||
|
||
it('should return a string when a string is passed', () => { | ||
expect(day2('a string')).to.be.a('string'); | ||
}); | ||
|
||
it('should return a number when a number is passed', () => { | ||
expect(day2(10)).to.be.a('Number'); | ||
}); | ||
|
||
it('should not be a string when a number is passed', () => { | ||
expect(day2(10)).to.not.be.a('string'); | ||
}); | ||
}); | ||
|
||
describe('checking equals', () => { | ||
it('should equal the string passed', () => { | ||
expect(day2('same string')).to.equal('same string'); | ||
}); | ||
|
||
it('should deep equal the object passed', () => { | ||
const givenObject = { | ||
hello: 'world' | ||
}; | ||
|
||
expect(day2(givenObject)).to.deep.equal(givenObject); | ||
}); | ||
}); | ||
|
||
describe('checking contains', () => { | ||
it('should contain part of the string passed', () => { | ||
const givenString = 'hello world'; | ||
|
||
expect(day2(givenString)).to.contain('world'); | ||
}); | ||
}); | ||
|
||
describe('checking errors', () => { | ||
it('should throw an error when "error" is passed', () => { | ||
function wrappedFunction() { | ||
day2('error'); | ||
} | ||
|
||
expect(wrappedFunction).to.throw('Cannot pass error'); | ||
}); | ||
}); | ||
}); |