Skip to content

Instantly share code, notes, and snippets.

@PavanKu
Created January 22, 2018 04:22
Show Gist options
  • Save PavanKu/a3de6a9ecd15a8bbcf18e58b8b221cf7 to your computer and use it in GitHub Desktop.
Save PavanKu/a3de6a9ecd15a8bbcf18e58b8b221cf7 to your computer and use it in GitHub Desktop.
Unit Testing of Model Class In AngularJS V5
import { Contact } from './contact';
describe('Contact', () => {
it('should create an instance', () => {
expect(new Contact()).toBeTruthy();
});
it('should accept values from constructor', () => {
let contact = new Contact({
firstName: 'John',
lastName: 'Reed'
});
expect(contact.firstName).toEqual('John');
expect(contact.lastName).toEqual('Reed');
expect(contact.id).toBeUndefined();
expect(contact.phone).toBeFalsy();
expect(contact.country).toBeFalsy();
});
it('contact#save should update the full name', () => {
let contact = new Contact({
firstName: 'Tony',
lastName: 'Stark',
phone: '+1 230130280',
country: 'United States of America'
});
expect(contact.fullName).toBeFalsy();
contact.save();
expect(contact.fullName).toEqual('Tony Stark');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment