Created
November 21, 2018 23:06
-
-
Save dpashkevich/8a238a92f2334a40217c0d9fb39eae4e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function greeter(person) { | |
if (!person || !person.firstName || !person.lastName) { | |
throw new Error('invalid arguments'); | |
} | |
return "Hello, " + person.firstName + " " + person.lastName; | |
} | |
// Jasmine spec: | |
describe("greeter", function() { | |
it("returns greeting on valid input", function() { | |
expect( | |
greeter({firstName: 'James', lastName: 'Hetfield'}) | |
).toEqual('Hello, James Hetfield'); | |
}); | |
it("throws on invalid input", function() { | |
expect(() => greeter()).toThrowError('invalid arguments'); | |
expect(() => greeter(5)).toThrowError('invalid arguments'); | |
expect(() => greeter({firstName: 'Jason'})).toThrowError('invalid arguments'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment