Skip to content

Commit 209e800

Browse files
authored
Merge branch 'master' into chore/validating-coverage
2 parents 036de1e + e3f44b7 commit 209e800

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

README.md

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
1-
Ionic Unit Testing Example
2-
=====================
1+
# Ionic Unit Testing Example
32

4-
This repository is an example project that gives guidance on setting up your Ionic application for unit testing and end-to-end (E2E) testing. We have been told the folks at Ionic will be adding testing features to new projects in the future. But until then, feel free to borrow from this project as needed.
3+
**This repository is an example project that gives guidance on setting up your Ionic application for unit testing and end-to-end (E2E) testing.** We have been told the folks at Ionic will be adding testing features to new projects in the future. But until then, feel free to borrow from this project as needed.
54

65
Special thanks to all of the contributors. With the exception of the Ionic team's updates to the framework, this project is stable. If you have a suggestion, feel free to update code and make a pull request. Find a problem or bug, feel free to file a detailed issue.
76

7+
## How to Configure Your Ionic Application for Testing
8+
9+
Read [this tutorial](https://leifwells.github.io/2017/08/27/testing-in-ionic-configure-existing-projects-for-testing/) for instructions on how to apply the testing configuration in this project to your own project.
10+
11+
## Mocking Classes for Ionic
12+
When a developer unit tests a component, the objective is to isolate that component as much as possible. In the case of an Ionic page, you may have Ionic components like `NavController`, `LoadingContoller`, or `Platform`. Adding these components means adding pieces of the Ionic framework to your test, thus not isolating the component. As part of this example, the file `test-config/mocks-ionic.ts` is provided for creating simple mocks for many of the classes in Ionic that you may need. You may use the classes from this file in test files inside the `TestBed.configureComponent()` method argument's `provider` array as seen in our [example unit test file](https://github.com/ionic-team/ionic-unit-testing-example/blob/master/src/app/app.component.spec.ts).
13+
14+
There are other mocking options that should be mentioned:
15+
**[ionic-mocks](https://github.com/stonelasley/ionic-mocks)**
16+
**[ionic-test-doubles](https://github.com/DomesticApp/ionic-test-doubles)**
17+
18+
Also worth mentioning is [ionic-native-mocks](https://github.com/chrisgriffith/ionic-native-mocks) which can be helpful when mocks for Ionic Native classes used in your project are needed.
19+
20+
Getting Started with this Project
21+
-----------
22+
23+
To get started, clone this repo, and run `npm install` in the root directory.
24+
25+
```sh
26+
git clone https://github.com/ionic-team/ionic-unit-test-example.git
27+
cd ionic-unit-testing-example
28+
npm install
29+
```
30+
Then, you should run `ionic serve` to make sure the project loads.
31+
32+
### Unit Tests
33+
34+
To run the tests, run `npm run test`.
35+
36+
See the example test in `src/app/app.component.spec.ts` for an example of a component test.
37+
38+
### End-To-End Tests (Browser-Only)
39+
40+
To serve the app, run `ionic serve`.
41+
42+
To run the end-to-end tests, run (while the app is being served) `npm run e2e`.
43+
44+
See the example end-to-end test in `e2e/app.e2e-spec.ts`.
45+
846
UPDATES:
947
--------
1048
### **2017-09-05: Added Code Coverage Functionality**
@@ -15,7 +53,16 @@ Thanks to @lathonez, we now have functioning code coverage functionality. With t
1553

1654
The documentation is created inside the `/coverage` folder (ignored by git).
1755

18-
## **Also of note:**
56+
## Looking for Version 2?
57+
58+
If you are using Ionic v2, please see our [ionic-v2-branch](https://github.com/ionic-team/ionic-unit-testing-example/tree/ionic-v2-branch).
59+
60+
## Credits
61+
62+
This repository is based on the awesome [unit testing example](https://github.com/roblouie/unit-testing-demo) from [@roblouie](https://github.com/roblouie/) :thumbsup:
63+
64+
Past Updates
65+
==========
1966

2067
### **2017-08-26: Update to `ionic-angular` version 3.6.0**
2168

@@ -25,17 +72,17 @@ We updated the project to `ionic-angular` version `3.6.0`. Developers wishing to
2572

2673
Thanks to [@datencia](https://github.com/datencia) for providing an update to our Karma configuration that properly sets the Karma base path so that image assets can be found during testing. This fix should also work any JSON data files you might want to use for testing. He also provided an image and updated our sample unit test spec file that tests that the image is found.
2774

28-
## **Added: Update code to match Ionic templates**
75+
#### **Added: Update code to match Ionic templates**
2976

3077
Thanks (again) to [@danielsogl](https://github.com/danielsogl/) for providing a code update to the project so that our code matches code created by using the `ionic start` command. Having this code properly match is important as it provides the best practice guidance for handling application start up.
3178

32-
### *2017-05-28: Update to Version 3.3.0*
79+
#### *2017-05-28: Update to Version 3.3.0*
3380

3481
Thanks to [@danielsogl](https://github.com/danielsogl/) for getting us up-to-date with Ionic 3.3.0, Angular 4.1.2 and Ionic Native 3.10.2.
3582

3683
Thanks to [@johnstonbl01](https://github.com/johnstonbl01/) for adding a couple of mocks that prevent us from seeing some unnecessary warning messages.
3784

38-
### *2017-05-12: Update to Version 3*
85+
#### *2017-05-12: Update to Version 3*
3986

4087
We've updated this repo to use Ionic v3.2.1 and Ionic CLI v3.0.0.
4188

@@ -47,35 +94,3 @@ npm remove -g ionic
4794
npm install -g ionic
4895
```
4996
If you run `ionic -v` it should return `3.0.0` (or better, depending on what has been released.
50-
51-
Looking for Version 2?
52-
----------------------
53-
54-
If you are using Ionic v2, please see our [ionic-v2-branch](https://github.com/ionic-team/ionic-unit-testing-example/tree/ionic-v2-branch).
55-
56-
57-
Credits
58-
=====================
59-
60-
This repository is based on the awesome [unit testing example](https://github.com/roblouie/unit-testing-demo) from [@roblouie](https://github.com/roblouie/) :thumbsup:
61-
62-
Getting Started
63-
===============
64-
65-
To get started, clone this repo, and run `npm install` in the root directory.
66-
67-
Unit Tests
68-
----------
69-
70-
To run the tests, run `npm test`.
71-
72-
See the example test in `src/app/app.component.spec.ts` for an example of a component test.
73-
74-
End-To-End Tests (Browser-Only)
75-
-------------------------------
76-
77-
To serve the app, run `ionic serve`.
78-
79-
To run the end-to-end tests, run (while the app is being served) `npm run e2e`.
80-
81-
See the example end-to-end test in `e2e/app.e2e-spec.ts`.

0 commit comments

Comments
 (0)