/
NOTE_TESTING.rtf
122 lines (100 loc) · 4.25 KB
/
NOTE_TESTING.rtf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
NOTE: before running protractor (e2e) tests, you must issue a command:
npm run update-webdriver
## TL;DR: ##
Default test run is
```
grunt test
```
Complete list of tests is at top of grunt.js file!
Adding tests:
You can add tests as client, server, or e2e tests. Details below:
===============================================================
===============================================================
===============================================================
## Client tests: ##
Runs KARMA tests and launches PhantomJS web browser.
Add files / patterns to lad in browser by modifying
```
karma.conf.js : config.set({
files: [ ADD FILES HERE ]})
```
===============================================================
===============================================================
===============================================================
## Server tests: ##
Runs MOCHA tests at /server/api/**/*.spec.js
You can add as many tests as you want, in any folder.
* Folders should each have at least 1 coverage test.
- Basic test looks like this:
'use strict';
var should = require('should');
var app = require('../../app');
var request = require('supertest'); // OPTIONAL, for serving/routing
var OBJECT = require('./OBJECT.model'); // OPTIONAL, for new instances of models (used for DB at the moment)
describe('Plain-English description of test to print to console', function() {
// OPTIONAL before step:
before(function(done) {
/* All work to do before testing, like clearing data. */
});
// OPTIONAL afterEach step:
afterEach(function(done) {
/* Maintenance to do after each step in testing, like clearing data. */
});
it('should (... Plain-English description of what the results should be)', function(done) {
/*********************************
* REFER TO MOCHA DOCUMENTATION: http://visionmedia.github.io/mocha/
* Write your test here, with the following steps:
*
* 1. Do the action
* 2. Specify expectations with chaining: .expect(RESULT)
* 3. Specify end with chaining: .end(function(err, res) { ... })
* 4. Handle errors: if (err) return done(err);
* if (err) function(err) { ... }
* 5. Run final / end-state tests: res.body.should.be.instanceof(Array);
* 6. Finish with done(); done()
* NOTE that 'done();' appears INSIDE the '.end()' function
*
* Full example below:
********************************/
request(app)
.get('/api/testAPI')
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
res.body.should.be.instanceof(Array);
done();
}); // end .end() function
}); // end it('should'...)
}); // end describe('test...')
===============================================================
===============================================================
===============================================================
## End-to-End (e2e) tests: ##
Runs PROTRACTOR tests with Jasmine framework in Chrome browser.
Protractor config file at: protractor.conf.js
Tests are in: /e2e/**/*.spec.js
- Basic test looks like this:
'use strict';
describe('Plain-English description of VIEW/PAGE being tested', function() {
var page;
beforeEach(function() {
browser.get('/');
page = require('./main.po');
});
it('should include (Plain-English text here of what is being tested on the page)', function() {
/*********************************
* REFER TO PROTRACTOR DOCUMENTATION: http://angular.github.io/protractor/#/
* Write your test here, with the following steps:
*
* 1. Specify expectations: .expect(RESULT)
* 2. Specify / select HTML attribute: (page.imgEl.getAttribute('src'))
* 3. Specify assertions with chaining: .toMatch(...); || .toBe(...);
*
* Full example below:
********************************/
expect(page.h1El.getText()).toBe('\'Allo, \'Allo!');
expect(page.imgEl.getAttribute('src')).toMatch(/assets\/images\/yeoman.png$/);
expect(page.imgEl.getAttribute('alt')).toBe('I\'m Yeoman');
}); // end it(should...)
}); // end describe()