Skip to content

Instantly share code, notes, and snippets.

@dpashkevich
Created November 21, 2018 23:06
Show Gist options
  • Save dpashkevich/8a238a92f2334a40217c0d9fb39eae4e to your computer and use it in GitHub Desktop.
Save dpashkevich/8a238a92f2334a40217c0d9fb39eae4e to your computer and use it in GitHub Desktop.
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