Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#8] Unit test for meetup component #37

Merged
merged 3 commits into from
Sep 20, 2017
Merged

[#8] Unit test for meetup component #37

merged 3 commits into from
Sep 20, 2017

Conversation

lucy811
Copy link
Member

@lucy811 lucy811 commented Sep 10, 2017

I used ng test to check the failure reasons.

  1. MeetupsaddComponent:
    Failed: Template parse errors: There is no directive with "exportAs" set to "ngForm" ("..
    I added import { FormsModule } from '@angular/forms'; and imports: [ FormsModule] in meetupsadd.component.spec.ts

2)Error: No provider for CouchService!
I added @component({ providers:[CouchService] }) in meetups.component.ts and meetupsadd.component.ts

3)Error: No provider for Http
Expected undefined to be truth
I added import { HttpModule } from '@angular/http'; and imports: [ HttpModule ], in meetups.component.spec.ts and meetupsadd.component.spec.ts

unittest1

unittest2

@lucy811 lucy811 changed the title Unit test for meetup component [#8] Unit test for meetup component Sep 11, 2017
Copy link
Member

@paulbert paulbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just make these small changes (after which the only files changed should be the 2 .spec.ts files).

Thanks!

@@ -3,6 +3,7 @@ import { CouchService } from '../shared/couchdb.service';

@Component({
templateUrl: './meetups.component.html',
providers:[CouchService]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This providers line should go into the configureTestingModule in the meetups.component.spec.ts file.

I had to read up to double check, but this actually instantiates a new CouchService class. While at this point it wouldn't break the app (the class isn't holding a shared state across components), for now we should stick with having a singleton service to connect to the DB.

@@ -16,7 +16,8 @@ import { CouchService } from '../shared/couchdb.service';
</div>
<button name="singlebutton" class="btn btn-primary" type="submit">Save</button>
</form>
`
`,
providers:[CouchService]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, please move this into the meetupsadd.component.spec.ts file

Copy link
Contributor

@empeje empeje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. You're creating a HTML test report. Next step is automatic testing and automatic reporting html https://github.com/ole-vi/planet/pull/24

@lucy811
Copy link
Member Author

lucy811 commented Sep 19, 2017

@paulbert I have moved providers:[CouchService] to .spec.ts files.

@paulbert paulbert merged commit 4f73a58 into master Sep 20, 2017
@paulbert paulbert deleted the 8-UnitTestMeetUp branch September 20, 2017 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants