midryndhil (2) [Avatar] Offline
#1
Hi,

Describe is used instead of it:

import { ContactsComponent } from './contacts.component';
describe('ContactsComponent Tests', () => {
let contactsComponent: Object = null;
beforeEach(() => {
contactsComponent = new ContactsComponent();
});
describe('The contacts component should have a valid constuctor', () => {
expect(contactsComponent).toBeAnInstanceOf(ContactsComponent);
});
describe('There should be no contacts if there is no data', () => {
expect(contactsComponent.contacts.length).toBe(0);
});
describe('There should be contacts if there is data', () => {
contactsComponent.contacts = [
{
id: 1,
name: 'Jason Pipemaker'
}];
expect(contactsComponent.contacts.length).toBe(1);
});
});


works with "it" :

import {ContactsComponent} from './contacts.component';

describe('ContactsComponent Tests', () => {
  let contactsComponent: ContactsComponent = null;
  beforeEach(() => {
    contactsComponent = new ContactsComponent();
  });
  it('The contacts component should have a valid constructor', () => {
    expect(contactsComponent).toBeDefined();
  });
  it('There should be no contacts if there is no data', () => {
    expect(contactsComponent.contacts.length).toBe(0);
  });
  it('There should be contacts if there is data', () => {
    contactsComponent.contacts = [
      {
        id: 1,
        name: 'Jason Pipemaker'
      }];
    expect(contactsComponent.contacts.length).toBe(1);
  });
});


the variable should be also of type contactsComponent and not object like in the listing.

Regards,
Jesse Palmer (44) [Avatar] Offline
#2
Thanks for catching these! They will be updated in the next version of the MEAP.