Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a63d87

Browse files
committed
update docs for mocha-coderoad@0.10 and next atom version
1 parentb23d74b commit9a63d87

File tree

4 files changed

+79
-29
lines changed

4 files changed

+79
-29
lines changed

‎_posts/tutorial-docs/2016-01-02-coderoad-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Defaults for loading tests are specified in the tutorial *package.json* file.
4444
"config": {
4545
"language":"JS",
4646
"dir":"tutorial",
47-
"testSuffix":".spec.js",
47+
"testSuffix":".js",
4848
"runner":"mocha-coderoad"
4949
}
5050
}

‎_posts/tutorial-docs/2016-01-04-loaders.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,58 @@ categories:
66
-tutorial-docs
77
---
88

9-
Loaders are hidden behind comments, which may differ based on theprogramming language or compiler.
9+
Use a**loader** to run the user saved file in thecontext of your file. Think of a loader as a way to place the file your testing inside of your test file.
1010

11-
#####JavaScript / TypeScript / JSX
11+
```js
12+
// paths are prefixed with "BASE"
13+
constuserTextEditorContent=require('BASE/path/to/file');
14+
constdataFile=require('BASE/path/to/data');
15+
```
1216

13-
`/// load('file.js')`
17+
The keyword "BASE" will be over-ridden with an absolute path to thefile.
1418

15-
#####Python
16-
`# load('file.py')`
19+
*Note: When using spies, stubs or mocks, initiate them above your loader call.*
20+
21+
22+
###Testing
23+
24+
If the editor exports a variable or function, units tests are easy to setup.
25+
26+
#####user file
27+
28+
```js
29+
exportconsta=1;
30+
```
31+
32+
#####unit test
33+
34+
```js
35+
expect(a).to.be(1);
36+
```
37+
38+
Otherwise, there is a slightly more complicated way to test globals.
39+
40+
###Unit Tests with Globals
41+
42+
Running unit tests on globals requires two additional steps.
43+
44+
1. capture the file as a module
45+
2. use a built-in`__get__` method to capture the target
46+
47+
#####user file
48+
49+
```js
50+
consta=1;
51+
```
52+
53+
#####unit test
54+
55+
```js
56+
// 1. capture the file's module.
57+
// Note that BASE will be replaced with an absolute path to the project dir
58+
constfile=require('BASE/path/to/file.js');
59+
// 2. use the __get__ method to capture the target variable
60+
consta=filter.__get__('a');
61+
62+
expect(a).to.be(1);
63+
```

‎_posts/tutorial-docs/2016-01-06-test-examples.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,67 @@ Here are examples using *mocha* with *chai*'s *expect*. See the [Chai/Expect doc
1111
####exists
1212

1313
```js
14-
it('doesn\'t exist',function() {
14+
it('doesn\'t exist',()=> {
1515
expect(target).to.be.defined;
1616
});
1717
```
1818

1919
####type
2020

2121
```js
22-
it('should be a function',function() {
22+
it('should be a function',()=> {
2323
expect(target).to.be.a('function');
2424
});
2525
```
2626

2727
####function params
2828

2929
```js
30-
it('should have two parameters',function() {
30+
it('should have two parameters',()=> {
3131
expect(target).to.have.length(2);
3232
});
3333
```
3434

3535
####function returns
3636

3737
```js
38-
it('should add one to the number',function () {
38+
it('should add one to the number',()=> {
3939
expect(addOne(1)).to.equal(2);
4040
});
4141
```
4242

4343
####equals
4444

4545
```js
46-
it('should be 42',function () {
46+
it('should be 42',()=> {
4747
expect(target).to.equal(42);
4848
});
4949
```
5050

5151
####deep equals (with objects or arrays)
5252

5353
```js
54-
it('should be {a: 42}',function () {
54+
it('should be {a: 42}',()=> {
5555
expect(target).to.deep.equal({a:42});
5656
});
5757
```
5858

5959
####regex
6060

6161
```js
62-
it('should include the variable "count"',function () {
63-
var regex=newRegExp('count');
64-
var string=target.toString();
62+
it('should include the variable "count"',()=> {
63+
constregex=newRegExp('count');
64+
conststring=target.toString();
6565
expect(string).to.match(regex);
6666
});
6767
```
6868

6969
```js
70-
it('should access the property "prop"',function () {
71-
var regex1=/\.prop/;// dot notation
72-
var regex2=/\[["']prop["']\]/;// bracket notation
73-
var string=target.toString();
74-
var result=!!string.match(regex1)||!!string.match(regex2);
70+
it('should access the property "prop"',()=> {
71+
constregex1=/\.prop/;// dot notation
72+
constregex2=/\[["']prop["']\]/;// bracket notation
73+
conststring=target.toString();
74+
constresult=!!string.match(regex1)||!!string.match(regex2);
7575
expect(result).to.be.true;
7676
});
7777
```
@@ -83,15 +83,18 @@ You can use [*sinon*](http://sinonjs.org/docs/) or [*chai-spies*](https://github
8383
`> npm i -s chai-spies`
8484

8585
```js
86-
var chai=require('chai'),
87-
spies=require('chai-spies');
88-
var expect=chai.expect;
89-
chai.use(spies);
86+
constchai=require('chai');
87+
constspies=require('chai-spies');
88+
constexpect=chai.expect;
89+
chai.use(spies);
9090

91-
var spy=chai.spy.on(console,'log');
92-
loadJS('04-forEach.js');
91+
// setup the console.logspy listener
92+
let spy=chai.spy.on(console,'log');
9393

94-
it('should write "hello world" to the console',function () {
94+
// load the user file content
95+
constexample=require('BASE/path/to/example.js');
96+
97+
it('should write "hello world" to the console', ()=> {
9598
expect(spy).to.have.been.called.with('hello world');
9699
});
97100
```
@@ -105,7 +108,7 @@ Some variables are passed into the test runner through the node environment *pro
105108
See an example of dynamic data based on the task position below:
106109

107110
```js
108-
var data= [1,2,3];
111+
constdata= [1,2,3];
109112

110113
if (process.env.TASK_POSITION==='4') {
111114
data= [1,2,3,4];

‎_posts/tutorial-docs/2016-01-07-config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ CodeRoad tutorial configurations can be set in the *package.json* config.
1212
"config": {
1313
"language":"JS",
1414
"dir":"tutorial",
15-
"testSuffix":".spec.js",
15+
"testSuffix":".js",
1616
"runner":"mocha-coderoad",
1717
"edit":true
1818
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp