mardi 18 avril 2017

Assistence clearing up Angular 2 Component Test Tutorial

I am trying to learn Angular's API for testing. I am currently reading the following tutorial:

http://ift.tt/2o0SvxJ

My understanding of how the following code works is not in line with what I am seeing while I am running the tests. As I understand the code, the second it method is reseting the elements content to 'Test Title' and checking for equality in the toContain method.

it('should display original title', () => {
  fixture.detectChanges();
  expect(el.textContent).toContain(comp.title);
});

it('should display a different test title', () => {
  comp.title = 'Test Title';
  fixture.detectChanges();
  expect(el.textContent).toContain('Test Title');
});

However when I play around with the code and make the following change from toContain('Test Title'); to toContain('Test'), the test still passes. This can be seen in the live example:

http://ift.tt/2okU9WZ

enter image description here

I get the same results in my own tests. I am assuming the test should fail but it does not.

Thanks.

Aucun commentaire:

Enregistrer un commentaire